From deb1b7f53d282ec04dfd73aabd085196daba4293 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 22 Nov 2024 13:42:29 -0800 Subject: [PATCH 1/3] adds option to configure smtp port. closes #79 --- index.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.py b/index.py index ff676e6..8729fa3 100755 --- a/index.py +++ b/index.py @@ -773,7 +773,7 @@ def _sendMail(config, from_addr, to_addr, subject, message): smtp = smtplib.SMTP timeout = config.get("SMTP_TIMEOUT", 30) try: - with smtp(config["SMTP_HOST"], timeout=timeout) as server: + with smtp(config["SMTP_HOST"], port=config["SMTP_PORT"], timeout=timeout) as server: if "SMTP_USERNAME" in config: try: server.login(config["SMTP_USERNAME"], config["SMTP_PASSWORD"]) @@ -806,6 +806,7 @@ def getConfig(): "SMTP_USERNAME", "SMTP_PASSWORD", "SMTP_TIMEOUT", + "SMTP_PORT", ]: if K in os.environ: config[K] = os.environ[K] From f6fa5a9a18c8c41eb460065d1a2132e735c27ff2 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 22 Nov 2024 13:57:38 -0800 Subject: [PATCH 2/3] add SMTP_TLS option --- index.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.py b/index.py index 8729fa3..b5f90ad 100755 --- a/index.py +++ b/index.py @@ -12,6 +12,7 @@ import requests_cache import ipaddress import smtplib +import ssl from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from email.header import Header @@ -774,6 +775,11 @@ def _sendMail(config, from_addr, to_addr, subject, message): timeout = config.get("SMTP_TIMEOUT", 30) try: with smtp(config["SMTP_HOST"], port=config["SMTP_PORT"], timeout=timeout) as server: + if "SMTP_TLS" in config: + connection.ehlo() + context = ssl.SSLContext(ssl.PROTOCOL_TLS) + connection.starttls(context=context) + connection.ehlo() if "SMTP_USERNAME" in config: try: server.login(config["SMTP_USERNAME"], config["SMTP_PASSWORD"]) @@ -801,6 +807,7 @@ def getConfig(): for K in [ "GH_OAUTH_TOKEN", "SMTP_SSL", + "SMTP_TLS", "SMTP_HOST", "EMAIL_FROM", "SMTP_USERNAME", From db00025e55c00520a9cf47027ca5b39156f3216f Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Fri, 22 Nov 2024 14:00:35 -0800 Subject: [PATCH 3/3] fix SMTP_TLS option --- index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.py b/index.py index b5f90ad..862f3e9 100755 --- a/index.py +++ b/index.py @@ -776,10 +776,10 @@ def _sendMail(config, from_addr, to_addr, subject, message): try: with smtp(config["SMTP_HOST"], port=config["SMTP_PORT"], timeout=timeout) as server: if "SMTP_TLS" in config: - connection.ehlo() + server.ehlo() context = ssl.SSLContext(ssl.PROTOCOL_TLS) - connection.starttls(context=context) - connection.ehlo() + server.starttls(context=context) + server.ehlo() if "SMTP_USERNAME" in config: try: server.login(config["SMTP_USERNAME"], config["SMTP_PASSWORD"])