Experimental change that adds configurable SMTP encryption mode

This commit is contained in:
Daniel Schick 2026-01-13 05:24:40 +01:00
parent dfb17d00eb
commit 62c13eb17a

View File

@ -110,11 +110,23 @@ def SendEmails(email_dict):
pooledConnection = getPoolConnection() pooledConnection = getPoolConnection()
commands = pydapper.using(pooledConnection) commands = pydapper.using(pooledConnection)
conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"]) encryption = defs.email_credentials.get("encryption") or defs.email_credentials.get("encryption_method") or "STARTTLS"
encryption_norm = str(encryption).strip().upper().replace(" ", "").replace("_", "").replace("-", "")
if encryption_norm in ("SSLTLS", "SSL", "TLS"):
conn = smtplib.SMTP_SSL(defs.email_credentials["server"], defs.email_credentials["port"])
else:
conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"])
conn.set_debuglevel(1) # set this to 0 to disable debug output to log conn.set_debuglevel(1) # set this to 0 to disable debug output to log
conn.ehlo() conn.ehlo()
conn.starttls() if encryption_norm in ("STARTTLS", "STARTSSL"):
conn.ehlo() conn.starttls()
conn.ehlo()
elif encryption_norm in ("NONE", "NO", "DISABLE"):
pass
elif encryption_norm not in ("SSLTLS", "SSL", "TLS"):
logging.warning("Unknown email encryption '%s'; defaulting to STARTTLS.", encryption)
conn.starttls()
conn.ehlo()
conn.login(defs.email_credentials["sender"], defs.email_credentials["password_send"]) conn.login(defs.email_credentials["sender"], defs.email_credentials["password_send"])
current_path = os.path.dirname(os.path.abspath(__file__)) current_path = os.path.dirname(os.path.abspath(__file__))