Added SMTP Auth support

This commit is contained in:
2017-12-22 10:59:15 +01:00
parent 8ca6b4cdb0
commit 054eced7de
2 changed files with 4 additions and 0 deletions

View File

@@ -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. # Send the message via local SMTP server.
try: try:
with smtplib.SMTP(cfg['SMTP_HOST'], cfg['SMTP_PORT'], timeout=cfg['SMTP_TIMEOUT']) as smtp: 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) smtp.send_message(msg)
except (IOError, OSError) as ex: except (IOError, OSError) as ex:
log.exception('error sending email to %s <%s>, will retry later: %s', log.exception('error sending email to %s <%s>, will retry later: %s',

View File

@@ -234,6 +234,8 @@ SUPPORT_ENGLISH = True
# Mail options, see pillar.celery.email_tasks. # Mail options, see pillar.celery.email_tasks.
SMTP_HOST = 'localhost' SMTP_HOST = 'localhost'
SMTP_PORT = 2525 SMTP_PORT = 2525
SMTP_USERNAME = ''
SMTP_PASSWORD = ''
SMTP_TIMEOUT = 30 # timeout in seconds, https://docs.python.org/3/library/smtplib.html#smtplib.SMTP 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_RETRY = 180 # in seconds, delay until trying to send an email again.
MAIL_DEFAULT_FROM_NAME = 'Blender Cloud' MAIL_DEFAULT_FROM_NAME = 'Blender Cloud'