From df107e6300713739dd8bba069c6deb16de0806ba Mon Sep 17 00:00:00 2001 From: hinak0 Date: Sun, 4 Sep 2022 19:12:36 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E9=82=AE=E7=AE=B1=E6=8E=A8=E9=80=81s?= =?UTF-8?q?sl=E5=8A=A0=E5=AF=86=E6=98=AF=E5=8F=AF=E9=80=89=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/push.ini.example | 6 +++++- push.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config/push.ini.example b/config/push.ini.example index cab2fdb..25dc681 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -43,11 +43,15 @@ priority=7 # 邮件推送 [smtp] +# 一般情况下,465端口会使用ssl加密默认465端口,不加密走25端口。 +# 例如qq邮箱为465端口,ssl加密;163邮箱不加密,使用25端口。 +# 请根据你的发送者邮箱配置端口和是否加密。 mailhost=smtp.qq.com port=465 +ssl_enable=true fromaddr=xxx@example.com toaddr=xxx@example.com -# 邮件标题 +# 邮件主题 subject=AutoMihoyoBBS username=xxx@example.com # 授权码 diff --git a/push.py b/push.py index cf928d9..ed6d5f5 100644 --- a/push.py +++ b/push.py @@ -77,7 +77,7 @@ def cqhttp(send_title, push_message): } ) -# ssl smtp mail +# smtp mail(电子邮件) # 感谢 @islandwind 提供的随机壁纸api 个人主页:https://space.bilibili.com/7600422 def smtp(send_title, push_message): import smtplib @@ -95,9 +95,13 @@ def smtp(send_title, push_message): message['Subject'] = cfg["smtp"]["subject"] message['To'] = cfg["smtp"]["toaddr"] message['From'] = f"{cfg['smtp']['subject']}<{cfg['smtp']['fromaddr']}>" - with smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port")) as server: - server.login(cfg["smtp"]["username"], cfg["smtp"]["password"]) - server.sendmail(cfg["smtp"]["fromaddr"], cfg["smtp"]["toaddr"], message.as_string()) + if cfg.getboolean("smtp","ssl_enable"): + server = smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port")) + else: + server = smtplib.SMTP(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port")) + server.login(cfg["smtp"]["username"], cfg["smtp"]["password"]) + server.sendmail(cfg["smtp"]["fromaddr"], cfg["smtp"]["toaddr"], message.as_string()) + server.close() log.info("邮件发送成功啦")