Skip to content

Commit

Permalink
Support SMTP port
Browse files Browse the repository at this point in the history
If port 25 is specified, start with plain SMTP and use STARTTLS only
when a password is provided
  • Loading branch information
wesselt committed Oct 8, 2023
1 parent 9ad9480 commit cf91414
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def send_mail(subject, body):
log.info("smtp_user or smtp_server not set, not sending email")
return
log.info("Sending exception email...")
port = int(config.get("smtp_port", 465))
log.info(f"Using port {port}...")
mail_to = config.get("smtp_to", user)
password = config.get("smtp_password", "")
mail_from = config.get("smtp_from", "bunq2ynab@" + get_hostname())
Expand All @@ -164,9 +166,14 @@ def send_mail(subject, body):
{body}
"""
smtp_server = smtplib.SMTP_SSL(server, 465)
if port == 25:
smtp_server = smtplib.SMTP(server, port=port, timeout=10)
else:
smtp_server = smtplib.SMTP_SSL(server, port=port, timeout=10)
smtp_server.ehlo()
if password:
if port == 25:
smtp_server.starttls()
smtp_server.login(user, password)
else:
log.info("smtp_password not set, not authenticating to server")
Expand Down

0 comments on commit cf91414

Please sign in to comment.