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"]