minor: 邮件背景图获取,邮件滚动文字显示优化

This commit is contained in:
hinak0 2022-09-03 15:41:07 +08:00
parent f221ae7d58
commit 17bb778d20
2 changed files with 16 additions and 6 deletions

View File

@ -9,18 +9,21 @@
</head> </head>
<body> <body>
<div class="cover"> <div class="cover" style="position: relative;">
<!-- 邮箱只解析行内样式 --> <!-- 邮箱只解析行内样式 -->
<img src="https://iw233.cn/api/Random.php" alt="background" style="width: 100%; <img src="{image_url}" alt="background" style="width: 100%;
filter: brightness(50%)"> filter: brightness(50%)">
<section style="position: fixed; width: 100%; <section style="position: absolute;
top: 10%; top: 0px;
left: 0; width: 100%;
text-align: center; text-align: center;
font-weight: 800;"> font-weight: 800;">
<!-- 添加阴影防止背景太鲜艳看不清文字 --> <!-- 添加阴影防止背景太鲜艳看不清文字 -->
<h2 style="color: #fff;text-shadow:0px 0px 10px #000;">{title}</h2> <h2 style="color: #fff;text-shadow:0px 0px 10px #000;">{title}</h2>
<p style="color: #fff;text-shadow:0px 0px 10px #000;">{message}</p> <p style="color: #fff;text-shadow:0px 0px 10px #000;">{message}</p>
<br />
<p style="color: #fff;text-shadow:0px 0px 10px #000;">背景图片链接</p>
<a href="{image_url}" style="color: #fff;text-shadow:0px 0px 10px #000;">{image_url}</a>
</section> </section>
</div> </div>
</body> </body>

View File

@ -78,12 +78,19 @@ def cqhttp(send_title, push_message):
) )
# ssl smtp mail # ssl smtp mail
# 感谢 @islandwind 提供的随机壁纸api 个人主页https://space.bilibili.com/7600422
def smtp(send_title, push_message): def smtp(send_title, push_message):
import smtplib import smtplib
from email.mime.text import MIMEText 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: with open("assets/email_example.html", encoding="utf-8") as f:
EMAIL_TEMPLATE = f.read() EMAIL_TEMPLATE = f.read()
message = EMAIL_TEMPLATE.format(title=send_title, message=push_message.replace("\n", "<br/>")) message = EMAIL_TEMPLATE.format(title=send_title, message=push_message.replace("\n", "<br/>"), image_url = image_url)
message = MIMEText(message, "html", "utf-8") message = MIMEText(message, "html", "utf-8")
message['Subject'] = cfg["smtp"]["subject"] message['Subject'] = cfg["smtp"]["subject"]
message['To'] = cfg["smtp"]["toaddr"] message['To'] = cfg["smtp"]["toaddr"]