Merge pull request #247 from hinak0/master

bugfix: 邮箱推送ssl加密是可选的
This commit is contained in:
Womsxd 2022-09-04 19:38:05 +08:00 committed by GitHub
commit e9c42d3a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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
# 授权码

12
push.py
View File

@ -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("邮件发送成功啦")