修复 notify.js smtp 通知

This commit is contained in:
whyour 2024-01-13 20:52:04 +08:00
parent 4e66a3aff5
commit 53346a3962
6 changed files with 23 additions and 39 deletions

View File

@ -149,11 +149,8 @@ export AIBOTK_TYPE=""
export AIBOTK_NAME=""
## 14. SMTP
## 暂时只支持在 Python 中调用 notify.py 以发送 SMTP 邮件通知
## smtp_server 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
export SMTP_SERVER=""
## smtp_ssl 填写 SMTP 发送邮件服务器是否使用 SSL内容应为 true 或 false
export SMTP_SSL="false"
## 邮箱服务名称比如126、163、Gmail、QQ等支持列表 https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json
export SMTP_SERVICE=""
## smtp_email 填写 SMTP 收发件邮箱,通知将会由自己发给自己
export SMTP_EMAIL=""
## smtp_password 填写 SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定

View File

@ -113,13 +113,6 @@ let IGOT_PUSH_KEY = '';
let PUSH_PLUS_TOKEN = '';
let PUSH_PLUS_USER = '';
// =======================================Cool Push设置区域=======================================
// 官方文档https://cp.xuthus.cc/docs
// QQ_SKEY: Cool Push登录授权后推送消息的调用代码Skey
// QQ_MODE: 推送模式详情请登录获取QQ_SKEY后见https://cp.xuthus.cc/feat
let QQ_SKEY = '';
let QQ_MODE = '';
// =======================================智能微秘书设置区域=======================================
// 官方文档http://wechat.aibotk.com/docs/about
// AIBOTK_KEY 填写智能微秘书个人中心的apikey
@ -135,13 +128,11 @@ let AIBOTK_NAME = '';
let FSKEY = '';
// =======================================SMTP 邮件设置区域=======================================
// SMTP_SERVER: 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
// SMTP_SSL: 填写 SMTP 发送邮件服务器是否使用 SSL内容应为 true 或 false
// SMTP_SERVICE: 邮箱服务名称比如126、163、Gmail、QQ等支持列表 https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json
// SMTP_EMAIL: 填写 SMTP 收发件邮箱,通知将会由自己发给自己
// SMTP_PASSWORD: 填写 SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
// SMTP_NAME: 填写 SMTP 收发件人姓名,可随意填写
let SMTP_SERVER = '';
let SMTP_SSL = 'false';
let SMTP_SERVICE = '';
let SMTP_EMAIL = '';
let SMTP_PASSWORD = '';
let SMTP_NAME = '';
@ -306,11 +297,8 @@ if (process.env.FSKEY) {
FSKEY = process.env.FSKEY;
}
if (process.env.SMTP_SERVER) {
SMTP_SERVER = process.env.SMTP_SERVER;
}
if (process.env.SMTP_SSL) {
SMTP_SSL = process.env.SMTP_SSL;
if (process.env.SMTP_SERVICE) {
SMTP_SERVICE = process.env.SMTP_SERVICE;
}
if (process.env.SMTP_EMAIL) {
SMTP_EMAIL = process.env.SMTP_EMAIL;
@ -1141,31 +1129,31 @@ function fsBotNotify(text, desp) {
}
async function smtpNotify(text, desp) {
if (![SMTP_SERVER, SMTP_EMAIL, SMTP_PASSWORD].every(Boolean)) {
if (![SMTP_EMAIL, SMTP_PASSWORD].every(Boolean) || !SMTP_SERVICE) {
return;
}
try {
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport(
`${SMTP_SSL === 'true' ? 'smtps:' : 'smtp:'}//${SMTP_SERVER}`,
{
auth: {
user: SMTP_EMAIL,
pass: SMTP_PASSWORD,
},
const transporter = nodemailer.createTransport({
service: SMTP_SERVICE,
auth: {
user: SMTP_EMAIL,
pass: SMTP_PASSWORD,
},
);
});
const addr = SMTP_NAME ? `"${SMTP_NAME}" <${SMTP_EMAIL}>` : SMTP_EMAIL;
const info = await transporter.sendMail({
from: addr,
to: addr,
subject: text,
text: desp,
html: `${desp.replace(/\n/g, '<br/>')}`,
});
if (!!info.messageId) {
transporter.close();
if (info.messageId) {
console.log('SMTP发送通知消息成功🎉\n');
return true;
}
@ -1311,11 +1299,9 @@ function webhookNotify(text, desp) {
got(formatUrl, options).then((resp) => {
try {
if (resp.statusCode !== 200) {
console.log('自定义发送通知消息失败!!\n');
console.log(resp.body);
console.log(`自定义发送通知消息失败!!\n${resp.body}`);
} else {
console.log('自定义发送通知消息成功🎉。\n');
console.log(resp.body);
console.log(`自定义发送通知消息成功🎉。\n${resp.body}`);
}
} catch (e) {
$.logErr(e, resp);

View File

@ -245,6 +245,7 @@ reload_qinglong() {
fi
if [[ "$reload_target" == 'data' ]]; then
rm -rf ${dir_root}/data
cp -rf ${dir_tmp}/data ${dir_root}/
fi

View File

@ -377,7 +377,7 @@
"飞书群组机器人https://www.feishu.cn/hc/zh-CN/articles/360024984973": "Feishu group bot: https://www.feishu.cn/hc/zh-CN/articles/360024984973",
"邮箱服务名称比如126、163、Gmail、QQ等支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "Email service name, e.g., 126, 163, Gmail, QQ, etc. Supported list: https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
"邮箱地址": "Email Address",
"邮箱SMTP授权码": "Email SMTP Authorization Code",
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "The SMTP login password may also be a special passphrase, depending on the specific email service provider's instructions",
"PushMe的Keyhttps://push.i-i.me/": "PushMe key, https://push.i-i.me/",
"请求方法": "Request Method",
"请求头Content-Type": "Request Header Content-Type",

View File

@ -377,7 +377,7 @@
"飞书群组机器人https://www.feishu.cn/hc/zh-CN/articles/360024984973": "飞书群组机器人https://www.feishu.cn/hc/zh-CN/articles/360024984973",
"邮箱服务名称比如126、163、Gmail、QQ等支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json": "邮箱服务名称比如126、163、Gmail、QQ等支持列表https://github.com/nodemailer/nodemailer/blob/master/lib/well-known/services.json",
"邮箱地址": "邮箱地址",
"邮箱SMTP授权码": "邮箱SMTP授权码",
"SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定": "SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定",
"PushMe的Keyhttps://push.i-i.me/": "PushMe的Keyhttps://push.i-i.me/",
"请求方法": "请求方法",
"请求头Content-Type": "请求头Content-Type",

View File

@ -325,7 +325,7 @@ export default {
required: true,
},
{ label: 'emailUser', tip: intl.get('邮箱地址'), required: true },
{ label: 'emailPass', tip: intl.get('邮箱SMTP授权码'), required: true },
{ label: 'emailPass', tip: intl.get('SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定'), required: true },
],
pushMe: [
{