From 667cdbcba3137cd9a14faaad033551c79433596e Mon Sep 17 00:00:00 2001 From: hinak0 Date: Fri, 2 Sep 2022 15:08:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=8E=A8=E9=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/email_example.html | 27 +++++++++++++++++++++++++++ config/push.ini.example | 20 ++++++++++++++++---- push.py | 29 +++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 assets/email_example.html 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): From 10ca2dcdd76332d4a167d3894919fe8c0c84262c Mon Sep 17 00:00:00 2001 From: hinak0 Date: Fri, 2 Sep 2022 16:00:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bugfix:=20=E4=BC=98=E5=8C=96=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/email_example.html | 12 ++++++------ push.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/email_example.html b/assets/email_example.html index d5d02e3..0da5406 100644 --- a/assets/email_example.html +++ b/assets/email_example.html @@ -13,15 +13,15 @@ background -
+ text-align: center; + font-weight: 800;">

{title}

-

{message}

+

{message}

- \ No newline at end of file + diff --git a/push.py b/push.py index 68f6032..3a68845 100644 --- a/push.py +++ b/push.py @@ -83,7 +83,7 @@ def smtp(send_title, push_message): 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 = EMAIL_TEMPLATE.format(title=send_title, message=push_message.replace("\n", "
")) message = MIMEText(message, "html", "utf-8") message['Subject'] = cfg["smtp"]["subject"] message['To'] = cfg["smtp"]["toaddr"]