Skip to content

Commit

Permalink
Merge pull request #80 from aaronpk/main
Browse files Browse the repository at this point in the history
adds port and TLS options for SMTP
  • Loading branch information
dontcallmedom authored Nov 26, 2024
2 parents 446a60a + db00025 commit aa653a6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -773,7 +774,12 @@ 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_TLS" in config:
server.ehlo()
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
server.starttls(context=context)
server.ehlo()
if "SMTP_USERNAME" in config:
try:
server.login(config["SMTP_USERNAME"], config["SMTP_PASSWORD"])
Expand Down Expand Up @@ -801,11 +807,13 @@ def getConfig():
for K in [
"GH_OAUTH_TOKEN",
"SMTP_SSL",
"SMTP_TLS",
"SMTP_HOST",
"EMAIL_FROM",
"SMTP_USERNAME",
"SMTP_PASSWORD",
"SMTP_TIMEOUT",
"SMTP_PORT",
]:
if K in os.environ:
config[K] = os.environ[K]
Expand Down

0 comments on commit aa653a6

Please sign in to comment.