From cc216df8143b81bdcf7957daddd4e895b691ae68 Mon Sep 17 00:00:00 2001
From: Womsxd <45663319+Womsxd@users.noreply.github.com>
Date: Fri, 4 Oct 2024 22:25:55 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20smtp(=E9=82=AE=E7=AE=B1)=E6=8E=A8?=
=?UTF-8?q?=E9=80=81=E5=8F=AF=E4=BB=A5=E5=85=B3=E9=97=AD=E8=83=8C=E6=99=AF?=
=?UTF-8?q?=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Womsxd <45663319+Womsxd@users.noreply.github.com>
---
assets/email_example.html | 6 ++----
config/push.ini.example | 2 ++
push.py | 31 ++++++++++++++++++++++++-------
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/assets/email_example.html b/assets/email_example.html
index 34c9bec..23bc8e3 100644
--- a/assets/email_example.html
+++ b/assets/email_example.html
@@ -11,8 +11,7 @@
-
+ {background_image}
{title}
{message}
- 背景图片链接
- {image_url}
+ {background_info}
diff --git a/config/push.ini.example b/config/push.ini.example
index 86f3377..fe79165 100644
--- a/config/push.ini.example
+++ b/config/push.ini.example
@@ -81,6 +81,8 @@ subject=AutoMihoyoBBS
username=xxx@example.com
# 授权码
password=passward
+# 背景 开关
+background = true
#webhook自定义推送
[webhook]
diff --git a/push.py b/push.py
index 691eb9b..dd0d536 100644
--- a/push.py
+++ b/push.py
@@ -121,17 +121,34 @@ def smtp(status_id, push_message):
import smtplib
from email.mime.text import MIMEText
- IMAGE_API = "https://api.iw233.cn/api.php?sort=random&type=json"
+ def get_background_url():
+ try:
+ _image_url = http.get("https://api.iw233.cn/api.php?sort=random&type=json").json()["pic"][0]
+ except:
+ _image_url = "unable to get the image"
+ log.warning("获取随机背景图失败,请检查图片api")
+ return _image_url
+
+ def get_background_img_html(background_url):
+ if background_url:
+ return f''
+ return ""
+
+ def get_background_img_info(background_url):
+ if background_url:
+ return f'p style="color: #fff;text-shadow:0px 0px 10px #000;">背景图片链接\n' \
+ f'{background_url}'
+ return ""
+
+ image_url = None
+ if cfg.getboolean('smtp', 'background', fallback=True):
+ image_url = get_background_url()
- try:
- image_url = http.get(IMAGE_API).json()["pic"][0]
- except:
- image_url = "unable to get the image"
- log.warning("获取随机背景图失败,请检查图片api")
with open("assets/email_example.html", encoding="utf-8") as f:
EMAIL_TEMPLATE = f.read()
message = EMAIL_TEMPLATE.format(title=get_push_title(status_id), message=push_message.replace("\n", "
"),
- image_url=image_url)
+ background_image=get_background_img_html(image_url),
+ background_info=get_background_img_info(image_url))
message = MIMEText(message, "html", "utf-8")
message['Subject'] = cfg["smtp"]["subject"]
message['To'] = cfg["smtp"]["toaddr"]