mirror of
https://github.com/whyour/qinglong.git
synced 2026-05-13 23:55:22 +08:00
新增支持多个接收邮箱,同步到node和系统内置版本
This commit is contained in:
parent
9b47912952
commit
c05aa5b0cd
|
|
@ -90,6 +90,14 @@ export default class NotificationService {
|
|||
return true;
|
||||
}
|
||||
|
||||
private parseMailRecipients(value?: string) {
|
||||
const recipients = (value || '')
|
||||
.split(/[;;]/)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
return recipients.length > 0 ? recipients : undefined;
|
||||
}
|
||||
|
||||
private async gotify() {
|
||||
const { gotifyUrl, gotifyToken, gotifyPriority = 1 } = this.params;
|
||||
try {
|
||||
|
|
@ -591,6 +599,7 @@ export default class NotificationService {
|
|||
|
||||
private async email() {
|
||||
const { emailPass, emailService, emailUser, emailTo } = this.params;
|
||||
const recipients = this.parseMailRecipients(emailTo) || emailUser;
|
||||
|
||||
try {
|
||||
const transporter = nodemailer.createTransport({
|
||||
|
|
@ -603,7 +612,7 @@ export default class NotificationService {
|
|||
|
||||
const info = await transporter.sendMail({
|
||||
from: `"青龙快讯" <${emailUser}>`,
|
||||
to: emailTo ? emailTo.split(';') : emailUser,
|
||||
to: recipients,
|
||||
subject: `${this.title}`,
|
||||
html: `${this.content.replace(/\n/g, '<br/>')}`,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -195,13 +195,13 @@ export SMTP_SERVER=""
|
|||
## SMTP 发送邮件服务器是否使用 SSL,填写 true 或 false
|
||||
export SMTP_SSL=""
|
||||
|
||||
## smtp_email 填写 SMTP 收发件邮箱,通知将会由自己发给自己
|
||||
## smtp_email 填写 SMTP 发件邮箱
|
||||
export SMTP_EMAIL=""
|
||||
## smtp_password 填写 SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||
export SMTP_PASSWORD=""
|
||||
## smtp_name 填写 SMTP 收发件人姓名,可随意填写
|
||||
export SMTP_NAME=""
|
||||
## smtp_email_to 填写 SMTP 收件邮箱,可选
|
||||
## smtp_email_to 填写 SMTP 收件邮箱,多个用英文;分隔,不填默认发给发件邮箱
|
||||
export SMTP_EMAIL_TO=""
|
||||
|
||||
## 17. PushMe
|
||||
|
|
|
|||
|
|
@ -121,7 +121,8 @@ const push_config = {
|
|||
|
||||
SMTP_SERVICE: '', // 邮箱服务名称,比如 126、163、Gmail、QQ 等,支持列表 https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json
|
||||
SMTP_EMAIL: '', // SMTP 发件邮箱
|
||||
SMTP_TO: '', // SMTP 收件邮箱,默认通知将会发给发件邮箱
|
||||
SMTP_TO: '', // SMTP 收件邮箱,兼容旧参数名,默认通知将会发给发件邮箱
|
||||
SMTP_EMAIL_TO: '', // SMTP 收件邮箱,多个分号分隔,默认发给发件邮箱
|
||||
SMTP_PASSWORD: '', // SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||
SMTP_NAME: '', // SMTP 收发件人姓名,可随意填写
|
||||
|
||||
|
|
@ -1046,8 +1047,14 @@ function fsBotNotify(text, desp) {
|
|||
}
|
||||
|
||||
async function smtpNotify(text, desp) {
|
||||
const { SMTP_EMAIL, SMTP_TO, SMTP_PASSWORD, SMTP_SERVICE, SMTP_NAME } =
|
||||
push_config;
|
||||
const {
|
||||
SMTP_EMAIL,
|
||||
SMTP_TO,
|
||||
SMTP_EMAIL_TO,
|
||||
SMTP_PASSWORD,
|
||||
SMTP_SERVICE,
|
||||
SMTP_NAME,
|
||||
} = push_config;
|
||||
if (![SMTP_EMAIL, SMTP_PASSWORD].every(Boolean) || !SMTP_SERVICE) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1063,9 +1070,20 @@ async function smtpNotify(text, desp) {
|
|||
});
|
||||
|
||||
const addr = SMTP_NAME ? `"${SMTP_NAME}" <${SMTP_EMAIL}>` : SMTP_EMAIL;
|
||||
const recipients = [SMTP_EMAIL_TO, SMTP_TO].reduce((list, value) => {
|
||||
if (!value) {
|
||||
return list;
|
||||
}
|
||||
return list.concat(
|
||||
value
|
||||
.split(/[;;]/)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
}, []);
|
||||
const info = await transporter.sendMail({
|
||||
from: addr,
|
||||
to: SMTP_TO ? SMTP_TO.split(';') : addr,
|
||||
to: recipients.length ? recipients : SMTP_EMAIL,
|
||||
subject: text,
|
||||
html: `${desp.replace(/\n/g, '<br/>')}`,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ push_config = {
|
|||
|
||||
'SMTP_SERVER': '', # SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||
'SMTP_SSL': 'false', # SMTP 发送邮件服务器是否使用 SSL,填写 true 或 false
|
||||
'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己
|
||||
'SMTP_EMAIL_TO': '', # SMTP 收件邮箱,填了则会发送到这个邮箱
|
||||
'SMTP_EMAIL': '', # SMTP 发件邮箱
|
||||
'SMTP_EMAIL_TO': '', # SMTP 收件邮箱,多个分号分隔,默认发给发件邮箱
|
||||
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||
'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写
|
||||
|
||||
|
|
@ -692,6 +692,9 @@ def smtp(title: str, content: str) -> None:
|
|||
print("SMTP 邮件 服务启动")
|
||||
|
||||
email_to = push_config.get("SMTP_EMAIL_TO") or push_config.get("SMTP_EMAIL")
|
||||
email_to_list = [
|
||||
item.strip() for item in re.split(r"[;;]", email_to) if item.strip()
|
||||
]
|
||||
message = MIMEText(content, "plain", "utf-8")
|
||||
message["From"] = formataddr(
|
||||
(
|
||||
|
|
@ -699,12 +702,7 @@ def smtp(title: str, content: str) -> None:
|
|||
push_config.get("SMTP_EMAIL"),
|
||||
)
|
||||
)
|
||||
message["To"] = formataddr(
|
||||
(
|
||||
Header(push_config.get("SMTP_NAME"), "utf-8").encode(),
|
||||
email_to,
|
||||
)
|
||||
)
|
||||
message["To"] = ",".join(email_to_list)
|
||||
message["Subject"] = Header(title, "utf-8")
|
||||
|
||||
try:
|
||||
|
|
@ -718,7 +716,7 @@ def smtp(title: str, content: str) -> None:
|
|||
)
|
||||
smtp_server.sendmail(
|
||||
push_config.get("SMTP_EMAIL"),
|
||||
email_to,
|
||||
email_to_list,
|
||||
message.as_bytes(),
|
||||
)
|
||||
smtp_server.close()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user