mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
SMTP 邮件通知支持收发分离、支持多收件人
This commit is contained in:
parent
a1501705c1
commit
1aa9a06989
|
@ -964,8 +964,8 @@ function fsBotNotify(text, desp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function smtpNotify(text, desp) {
|
async function smtpNotify(text, desp) {
|
||||||
const { SMTP_EMAIL, SMTP_PASSWORD, SMTP_SERVICE, SMTP_NAME } = push_config;
|
const { SMTP_EMAIL, SMTP_PASSWORD, SMTP_SERVICE, SMTP_NAME, SMTP_EMAIL_TO, SMTP_NAME_TO } = push_config;
|
||||||
if (![SMTP_EMAIL, SMTP_PASSWORD].every(Boolean) || !SMTP_SERVICE) {
|
if (!SMTP_EMAIL || !SMTP_PASSWORD || !SMTP_SERVICE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -979,10 +979,24 @@ async function smtpNotify(text, desp) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const addr = SMTP_NAME ? `"${SMTP_NAME}" <${SMTP_EMAIL}>` : SMTP_EMAIL;
|
const fromAddr = SMTP_NAME ? `"${SMTP_NAME}" <${SMTP_EMAIL}>` : SMTP_EMAIL;
|
||||||
|
|
||||||
|
let toAddr;
|
||||||
|
if (SMTP_EMAIL_TO) {
|
||||||
|
// 处理多个收件人
|
||||||
|
const emailTos = SMTP_EMAIL_TO.split(',');
|
||||||
|
const nameTos = (SMTP_NAME_TO || "").split(',');
|
||||||
|
toAddr = emailTos.map((email, index) => {
|
||||||
|
const name = nameTos[index] || "";
|
||||||
|
return name ? `"${name}" <${email}>` : email;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toAddr = fromAddr;
|
||||||
|
}
|
||||||
|
|
||||||
const info = await transporter.sendMail({
|
const info = await transporter.sendMail({
|
||||||
from: addr,
|
from: fromAddr,
|
||||||
to: addr,
|
to: toAddr,
|
||||||
subject: text,
|
subject: text,
|
||||||
html: `${desp.replace(/\n/g, '<br/>')}`,
|
html: `${desp.replace(/\n/g, '<br/>')}`,
|
||||||
});
|
});
|
||||||
|
|
|
@ -101,9 +101,11 @@ push_config = {
|
||||||
|
|
||||||
'SMTP_SERVER': '', # SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
'SMTP_SERVER': '', # SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||||
'SMTP_SSL': 'false', # SMTP 发送邮件服务器是否使用 SSL,填写 true 或 false
|
'SMTP_SSL': 'false', # SMTP 发送邮件服务器是否使用 SSL,填写 true 或 false
|
||||||
'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己
|
'SMTP_EMAIL': '', # SMTP 发件邮箱
|
||||||
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||||
'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写
|
'SMTP_NAME': '', # SMTP 发件人姓名,可随意填写
|
||||||
|
'SMTP_EMAIL_TO': '', # SMTP 收件邮箱,可选,缺省时将自己发给自己,多个收件邮箱逗号间隔
|
||||||
|
'SMTP_NAME_TO': '', # SMTP 收件人姓名,可选,可随意填写,多个收件人逗号间隔,顺序与 SMTP_EMAIL_TO 保持一致
|
||||||
|
|
||||||
'PUSHME_KEY': '', # PushMe 的 PUSHME_KEY
|
'PUSHME_KEY': '', # PushMe 的 PUSHME_KEY
|
||||||
'PUSHME_URL': '', # PushMe 的 PUSHME_URL
|
'PUSHME_URL': '', # PushMe 的 PUSHME_URL
|
||||||
|
@ -679,12 +681,23 @@ def smtp(title: str, content: str) -> None:
|
||||||
push_config.get("SMTP_EMAIL"),
|
push_config.get("SMTP_EMAIL"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
message["To"] = formataddr(
|
if not push_config.get("SMTP_EMAIL_TO"):
|
||||||
(
|
smtp_email_to = push_config.get("SMTP_EMAIL")
|
||||||
Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
|
message["To"] = formataddr(
|
||||||
push_config.get("SMTP_EMAIL"),
|
(
|
||||||
|
Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
|
||||||
|
push_config.get("SMTP_EMAIL"),
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
else:
|
||||||
|
smtp_email_to = push_config.get("SMTP_EMAIL_TO").split(",")
|
||||||
|
smtp_name_to = push_config.get("SMTP_NAME_TO","").split(",")
|
||||||
|
message["To"] = ",".join([formataddr(
|
||||||
|
(
|
||||||
|
Header(smtp_name_to[i] if len(smtp_name_to) > i else "", "utf-8").encode(),
|
||||||
|
email_to,
|
||||||
|
)
|
||||||
|
) for i, email_to in enumerate(smtp_email_to)])
|
||||||
message["Subject"] = Header(title, "utf-8")
|
message["Subject"] = Header(title, "utf-8")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -698,7 +711,7 @@ def smtp(title: str, content: str) -> None:
|
||||||
)
|
)
|
||||||
smtp_server.sendmail(
|
smtp_server.sendmail(
|
||||||
push_config.get("SMTP_EMAIL"),
|
push_config.get("SMTP_EMAIL"),
|
||||||
push_config.get("SMTP_EMAIL"),
|
smtp_email_to,
|
||||||
message.as_bytes(),
|
message.as_bytes(),
|
||||||
)
|
)
|
||||||
smtp_server.close()
|
smtp_server.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user