From 054eced7de158d8df4b5f17376abe89c3d4fa354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 22 Dec 2017 10:59:15 +0100 Subject: [PATCH] Added SMTP Auth support --- pillar/celery/email_tasks.py | 2 ++ pillar/config.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pillar/celery/email_tasks.py b/pillar/celery/email_tasks.py index e6612c2a..6e1b0278 100644 --- a/pillar/celery/email_tasks.py +++ b/pillar/celery/email_tasks.py @@ -39,6 +39,8 @@ def send_email(self: celery.Task, to_name: str, to_addr: str, subject: str, text # Send the message via local SMTP server. try: with smtplib.SMTP(cfg['SMTP_HOST'], cfg['SMTP_PORT'], timeout=cfg['SMTP_TIMEOUT']) as smtp: + if cfg.get('SMTP_USERNAME') and cfg.get('SMTP_PASSWORD'): + smtp.login(cfg['SMTP_USERNAME'], cfg['SMTP_PASSWORD']) smtp.send_message(msg) except (IOError, OSError) as ex: log.exception('error sending email to %s <%s>, will retry later: %s', diff --git a/pillar/config.py b/pillar/config.py index 261b12e5..9990c574 100644 --- a/pillar/config.py +++ b/pillar/config.py @@ -234,6 +234,8 @@ SUPPORT_ENGLISH = True # Mail options, see pillar.celery.email_tasks. SMTP_HOST = 'localhost' SMTP_PORT = 2525 +SMTP_USERNAME = '' +SMTP_PASSWORD = '' SMTP_TIMEOUT = 30 # timeout in seconds, https://docs.python.org/3/library/smtplib.html#smtplib.SMTP MAIL_RETRY = 180 # in seconds, delay until trying to send an email again. MAIL_DEFAULT_FROM_NAME = 'Blender Cloud'