diff --git a/arbiter/actions.py b/arbiter/actions.py index e1b197f..8259e66 100644 --- a/arbiter/actions.py +++ b/arbiter/actions.py @@ -296,9 +296,14 @@ def send_email(subject, html_message, to, bcc, sender, image_attachment=None, # Send the message if email["bcc"] or email["to"]: - mail_server = cfg.email.mail_server + mail_server = cfg.email.mail_server + smtp_starttls = cfg.email.smtp_starttls + smtp_passwd = cfg.email.smtp_passwd try: with smtplib.SMTP(mail_server) as smtp: + if (smtp_starttls == True and smtp_passwd != ''): + smtp.starttls() # Start TLS encryption + smtp.login(email["From"], smtp_passwd) # Login smtp.send_message(email) except Exception as err: logger.debug(err) diff --git a/arbiter/cfgparser.py b/arbiter/cfgparser.py index 3a8255f..764fb25 100755 --- a/arbiter/cfgparser.py +++ b/arbiter/cfgparser.py @@ -379,6 +379,8 @@ def redacted_url(url): "email": { "email_domain": ValidationProtocol(str), "from_email": ValidationProtocol(str), + "smtp_passwd": ValidationProtocol(str,default_value=""), + "smtp_starttls": ValidationProtocol(bool,default_value=False), "admin_emails": ValidationProtocol(list, all_are_str), "mail_server": ValidationProtocol(str, can_ping), "keep_plots": ValidationProtocol(bool), diff --git a/etc/config.toml b/etc/config.toml index 0dd16eb..1e425a2 100644 --- a/etc/config.toml +++ b/etc/config.toml @@ -21,6 +21,8 @@ time_to_min_bad = 1800 # 30 minutes [email] email_domain = 'organization.edu' # Used for a generic email addr integration in integrations.py from_email = 'noreply+arbiter@organization.edu' +smtp_passwd = '' # Password used for logging in to the SMTP server with from_email and smtp_passwd. +smtp_starttls = True # If True, enables STARTTLS to secure the SMTP connection. Default is False. admin_emails = ['john.doe@organization.edu'] mail_server = '0.0.0.0' keep_plots = false diff --git a/etc/integrations.py b/etc/integrations.py index 5b151c4..7ec2173 100644 --- a/etc/integrations.py +++ b/etc/integrations.py @@ -310,7 +310,7 @@ def email_addr_placeholder(username): username: str The username of the user. """ - return ("{}@" + cfg.email.email_domain).format(username) + return ("v.{}@" + cfg.email.email_domain).format(username) def _get_name(uid):