mirror of
https://github.com/TDSCDMAA/AutoMihoyoBBS.git
synced 2026-06-02 18:43:42 +08:00
feat: 增加邮件推送功能
This commit is contained in:
parent
f9ec3fa968
commit
667cdbcba3
27
assets/email_example.html
Normal file
27
assets/email_example.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>AutoMihoyoBBS</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="cover">
|
||||
<!-- 邮箱只解析行内样式 -->
|
||||
<img src="https://iw233.cn/api/Random.php" alt="background" style="width: 100%;
|
||||
filter: brightness(80%)">
|
||||
<section style="position: fixed;
|
||||
width: 100%;
|
||||
top: 30%;
|
||||
left: 0;
|
||||
text-align: center;">
|
||||
<h2>{title}</h2>
|
||||
<h3>{message}</h3>
|
||||
</section>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@ -1,7 +1,7 @@
|
||||
[setting]
|
||||
enable=false
|
||||
#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot bark pushdeer gotify
|
||||
push_server=cqhttp
|
||||
enable=true
|
||||
#共有 cqhttp ftqq(sever酱) pushplus telegram wecom dingrobot bark pushdeer gotify email
|
||||
push_server=smtp
|
||||
#server酱 pushplus dingrobot 的推送token
|
||||
push_token=123456
|
||||
|
||||
@ -39,4 +39,16 @@ token=ssXXX
|
||||
[gotify]
|
||||
api_url=http://xxx.xxx.cn
|
||||
token=AMxxxx
|
||||
priority=7
|
||||
priority=7
|
||||
|
||||
# 邮件推送
|
||||
[smtp]
|
||||
mailhost=smtp.qq.com
|
||||
port=465
|
||||
fromaddr=xxx@example.com
|
||||
toaddr=xxx@example.com
|
||||
# 邮件标题
|
||||
subject=AutoMihoyoBBS
|
||||
username=xxx@example.com
|
||||
# 授权码
|
||||
password=passward
|
||||
|
||||
29
push.py
29
push.py
@ -1,14 +1,15 @@
|
||||
import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
import os
|
||||
import time
|
||||
import hmac
|
||||
import base64
|
||||
import config
|
||||
import urllib
|
||||
import hashlib
|
||||
from request import http
|
||||
from loghelper import log
|
||||
from configparser import ConfigParser
|
||||
|
||||
import config
|
||||
from loghelper import log
|
||||
from request import http
|
||||
|
||||
cfg = ConfigParser()
|
||||
|
||||
|
||||
@ -76,6 +77,22 @@ def cqhttp(send_title, push_message):
|
||||
}
|
||||
)
|
||||
|
||||
# ssl smtp mail
|
||||
def smtp(send_title, push_message):
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
with open("assets/email_example.html") as f:
|
||||
EMAIL_TEMPLATE = f.read()
|
||||
message = EMAIL_TEMPLATE.format(title=send_title, message=push_message)
|
||||
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']}>"
|
||||
with smtplib.SMTP_SSL(cfg["smtp"]["mailhost"], cfg.getint("smtp", "port")) as server:
|
||||
server.login(cfg["smtp"]["username"], cfg["smtp"]["password"])
|
||||
server.sendmail(cfg["smtp"]["fromaddr"], cfg["smtp"]["toaddr"], message.as_string())
|
||||
log.info("邮件发送成功啦")
|
||||
|
||||
|
||||
# 企业微信 感谢linjie5492@github
|
||||
def wecom(send_title, push_message):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user