commit
e9c42d3a73
@ -43,11 +43,15 @@ priority=7
|
|||||||
|
|
||||||
# 邮件推送
|
# 邮件推送
|
||||||
[smtp]
|
[smtp]
|
||||||
|
# 一般情况下,465端口会使用ssl加密默认465端口,不加密走25端口。
|
||||||
|
# 例如qq邮箱为465端口,ssl加密;163邮箱不加密,使用25端口。
|
||||||
|
# 请根据你的发送者邮箱配置端口和是否加密。
|
||||||
mailhost=smtp.qq.com
|
mailhost=smtp.qq.com
|
||||||
port=465
|
port=465
|
||||||
|
ssl_enable=true
|
||||||
fromaddr=xxx@example.com
|
fromaddr=xxx@example.com
|
||||||
toaddr=xxx@example.com
|
toaddr=xxx@example.com
|
||||||
# 邮件标题
|
# 邮件主题
|
||||||
subject=AutoMihoyoBBS
|
subject=AutoMihoyoBBS
|
||||||
username=xxx@example.com
|
username=xxx@example.com
|
||||||
# 授权码
|
# 授权码
|
||||||
|
12
push.py
12
push.py
@ -77,7 +77,7 @@ def cqhttp(send_title, push_message):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# ssl smtp mail
|
# smtp mail(电子邮件)
|
||||||
# 感谢 @islandwind 提供的随机壁纸api 个人主页:https://space.bilibili.com/7600422
|
# 感谢 @islandwind 提供的随机壁纸api 个人主页:https://space.bilibili.com/7600422
|
||||||
def smtp(send_title, push_message):
|
def smtp(send_title, push_message):
|
||||||
import smtplib
|
import smtplib
|
||||||
@ -95,9 +95,13 @@ def smtp(send_title, push_message):
|
|||||||
message['Subject'] = cfg["smtp"]["subject"]
|
message['Subject'] = cfg["smtp"]["subject"]
|
||||||
message['To'] = cfg["smtp"]["toaddr"]
|
message['To'] = cfg["smtp"]["toaddr"]
|
||||||
message['From'] = f"{cfg['smtp']['subject']}<{cfg['smtp']['fromaddr']}>"
|
message['From'] = f"{cfg['smtp']['subject']}<{cfg['smtp']['fromaddr']}>"
|
||||||
with smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port")) as server:
|
if cfg.getboolean("smtp","ssl_enable"):
|
||||||
server.login(cfg["smtp"]["username"], cfg["smtp"]["password"])
|
server = smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port"))
|
||||||
server.sendmail(cfg["smtp"]["fromaddr"], cfg["smtp"]["toaddr"], message.as_string())
|
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("邮件发送成功啦")
|
log.info("邮件发送成功啦")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user