From dd7ed3b75152ad90f08dc5f8af70fd828e8585bb Mon Sep 17 00:00:00 2001 From: baiyong Date: Sun, 1 Dec 2024 16:04:52 +0800 Subject: [PATCH] FIX smtp error --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c8762bd..2290bb6 100644 --- a/main.py +++ b/main.py @@ -106,11 +106,12 @@ def _format_addr(s): today = datetime.datetime.now().strftime('%Y/%m/%d') msg['Subject'] = Header(f'Daily arXiv {today}', 'utf-8').encode() - if smtp_server == 'smtp.qq.com': - server = smtplib.SMTP_SSL(smtp_server, smtp_port) - else: + try: server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() + except smtplib.SMTPServerDisconnected: + server = smtplib.SMTP_SSL(smtp_server, smtp_port) + server.login(sender, password) server.sendmail(sender, [receiver], msg.as_string()) server.quit()