From 17bb778d20058aa9b25ce664504dfdf463244d09 Mon Sep 17 00:00:00 2001 From: hinak0 Date: Sat, 3 Sep 2022 15:41:07 +0800 Subject: [PATCH] =?UTF-8?q?minor:=20=E9=82=AE=E4=BB=B6=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9B=BE=E8=8E=B7=E5=8F=96=EF=BC=8C=E9=82=AE=E4=BB=B6=E6=BB=9A?= =?UTF-8?q?=E5=8A=A8=E6=96=87=E5=AD=97=E6=98=BE=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/email_example.html | 13 ++++++++----- push.py | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/assets/email_example.html b/assets/email_example.html index e369328..34c9bec 100644 --- a/assets/email_example.html +++ b/assets/email_example.html @@ -9,18 +9,21 @@ -
+
- background -

{title}

{message}

+
+

背景图片链接

+ {image_url}
diff --git a/push.py b/push.py index 760be37..cf928d9 100644 --- a/push.py +++ b/push.py @@ -78,12 +78,19 @@ def cqhttp(send_title, push_message): ) # ssl smtp mail +# 感谢 @islandwind 提供的随机壁纸api 个人主页:https://space.bilibili.com/7600422 def smtp(send_title, push_message): import smtplib from email.mime.text import MIMEText + + try: + image_url = http.get("https://iw233.cn/api.php?sort=random&type=json").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=send_title, message=push_message.replace("\n", "
")) + message = EMAIL_TEMPLATE.format(title=send_title, message=push_message.replace("\n", "
"), image_url = image_url) message = MIMEText(message, "html", "utf-8") message['Subject'] = cfg["smtp"]["subject"] message['To'] = cfg["smtp"]["toaddr"]