Skip to content

Commit

Permalink
Merge pull request #45 from TideDra:hotfix_smtptls
Browse files Browse the repository at this point in the history
catch all starttls error
  • Loading branch information
TideDra authored Jan 7, 2025
2 parents 6903ffe + b871c3f commit 4552754
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion construct_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from email.utils import parseaddr, formataddr
import smtplib
import datetime
from loguru import logger

framework = """
<!DOCTYPE HTML>
Expand Down Expand Up @@ -152,7 +153,9 @@ def _format_addr(s):
try:
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
except smtplib.SMTPServerDisconnected:
except Exception as e:
logger.warning(f"Failed to use TLS. {e}")
logger.warning(f"Try to use SSL.")
server = smtplib.SMTP_SSL(smtp_server, smtp_port)

server.login(sender, password)
Expand Down

0 comments on commit 4552754

Please sign in to comment.