Skip to content

Commit

Permalink
catch all starttls error
Browse files Browse the repository at this point in the history
  • Loading branch information
TideDra committed Jan 7, 2025
1 parent 6903ffe commit b871c3f
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 b871c3f

Please sign in to comment.