diff --git a/assets/email_example.html b/assets/email_example.html new file mode 100644 index 0000000..d5d02e3 --- /dev/null +++ b/assets/email_example.html @@ -0,0 +1,27 @@ + + + + + + + + AutoMihoyoBBS + + + +
+ + background +
+

{title}

+

{message}

+
+
+ + + \ No newline at end of file diff --git a/config/push.ini.example b/config/push.ini.example index b39cb64..fbe0574 100644 --- a/config/push.ini.example +++ b/config/push.ini.example @@ -1,7 +1,7 @@ [setting] -enable=false -#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot bark pushdeer gotify -push_server=cqhttp +enable=true +#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot bark pushdeer gotify email +push_server=smtp #server酱 pushplus dingrobot 的推送token push_token=123456 @@ -39,4 +39,16 @@ token=ssXXX [gotify] api_url=http://xxx.xxx.cn token=AMxxxx -priority=7 \ No newline at end of file +priority=7 + +# 邮件推送 +[smtp] +mailhost=smtp.qq.com +port=465 +fromaddr=xxx@example.com +toaddr=xxx@example.com +# 邮件标题 +subject=AutoMihoyoBBS +username=xxx@example.com +# 授权码 +password=passward diff --git a/push.py b/push.py index 8a52410..68f6032 100644 --- a/push.py +++ b/push.py @@ -1,14 +1,15 @@ +import base64 +import hashlib +import hmac import os import time -import hmac -import base64 -import config import urllib -import hashlib -from request import http -from loghelper import log from configparser import ConfigParser +import config +from loghelper import log +from request import http + cfg = ConfigParser() @@ -76,6 +77,22 @@ def cqhttp(send_title, push_message): } ) +# ssl smtp mail +def smtp(send_title, push_message): + import smtplib + from email.mime.text import MIMEText + with open("assets/email_example.html") as f: + EMAIL_TEMPLATE = f.read() + message = EMAIL_TEMPLATE.format(title=send_title, message=push_message) + message = MIMEText(message, "html", "utf-8") + 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()) + log.info("邮件发送成功啦") + # 企业微信 感谢linjie5492@github def wecom(send_title, push_message):