Skip to content

Commit aa653a6

Browse files
Merge pull request #80 from aaronpk/main
adds port and TLS options for SMTP
2 parents 446a60a + db00025 commit aa653a6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import requests_cache
1313
import ipaddress
1414
import smtplib
15+
import ssl
1516
from email.mime.text import MIMEText
1617
from email.mime.multipart import MIMEMultipart
1718
from email.header import Header
@@ -773,7 +774,12 @@ def _sendMail(config, from_addr, to_addr, subject, message):
773774
smtp = smtplib.SMTP
774775
timeout = config.get("SMTP_TIMEOUT", 30)
775776
try:
776-
with smtp(config["SMTP_HOST"], timeout=timeout) as server:
777+
with smtp(config["SMTP_HOST"], port=config["SMTP_PORT"], timeout=timeout) as server:
778+
if "SMTP_TLS" in config:
779+
server.ehlo()
780+
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
781+
server.starttls(context=context)
782+
server.ehlo()
777783
if "SMTP_USERNAME" in config:
778784
try:
779785
server.login(config["SMTP_USERNAME"], config["SMTP_PASSWORD"])
@@ -801,11 +807,13 @@ def getConfig():
801807
for K in [
802808
"GH_OAUTH_TOKEN",
803809
"SMTP_SSL",
810+
"SMTP_TLS",
804811
"SMTP_HOST",
805812
"EMAIL_FROM",
806813
"SMTP_USERNAME",
807814
"SMTP_PASSWORD",
808815
"SMTP_TIMEOUT",
816+
"SMTP_PORT",
809817
]:
810818
if K in os.environ:
811819
config[K] = os.environ[K]

0 commit comments

Comments
 (0)