Commit 8b46db1a authored by Huihui, Jonathan's avatar Huihui, Jonathan
Browse files

add relay user to specify actual email address

parent afee08c3
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ def send_email(subject, text, files=None, recipients=None):
    relay_address = ce('RELAY_ADDRESS')
    relay_port = ce('RELAY_PORT')
    relay_password = ce('RELAY_PASSWORD')
    relay_user = ce('RELAY_USER')
    smtp_port = ce('SMTP_PORT', 25)
    if from_address is None:
        logger.critical('Unable to send email as no EMAIL_SENDER set')
@@ -84,13 +85,13 @@ def send_email(subject, text, files=None, recipients=None):
            server.quit()
        logger.info(f'Email successfully sent to {to_address}.')
    elif all(var is not None for var in [relay_address, relay_port,
                                         relay_password]):
                                         relay_password, relay_user]):
        # allow ssl connection
        context = ssl.create_default_context()
        with smtplib.SMTP(relay_address, relay_port) as conn:
            conn.ehlo()
            conn.starttls(context=context)
            conn.login(from_address, relay_password)
            conn.login(relay_user, relay_password)
            conn.send_message(msg)
            conn.quit()
        logger.info(f'Email successfully sent to {to_address}.')