commit
0b99641150
8
push.py
8
push.py
@ -83,19 +83,21 @@ def smtp(send_title, push_message):
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
IMAGE_API = "http://api.iw233.cn/api.php?sort=random&type=json"
|
||||
|
||||
try:
|
||||
image_url = http.get("https://iw233.cn/api.php?sort=random&type=json").json()["pic"][0]
|
||||
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=send_title, message=push_message.replace("\n", "<br/>"), image_url = image_url)
|
||||
message = EMAIL_TEMPLATE.format(title=send_title, message=push_message.replace("\n", "<br/>"), image_url=image_url)
|
||||
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']}>"
|
||||
if cfg.getboolean("smtp","ssl_enable"):
|
||||
if cfg.getboolean("smtp", "ssl_enable"):
|
||||
server = smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port"))
|
||||
else:
|
||||
server = smtplib.SMTP(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port"))
|
||||
|
Loading…
Reference in New Issue
Block a user