do not pass smtp user/pass to nodemailer if both are empty

This commit is contained in:
LouisLam 2021-08-17 01:26:21 +08:00
parent fc76c2836b
commit 31d5b4fd3d

View File

@ -197,9 +197,9 @@ class Notification {
try { try {
let config = { let config = {
headers: { headers: {
'api-key': notification.octopushAPIKey, "api-key": notification.octopushAPIKey,
'api-login': notification.octopushLogin, "api-login": notification.octopushLogin,
'cache-control': 'no-cache' "cache-control": "no-cache"
} }
}; };
let data = { let data = {
@ -215,7 +215,7 @@ class Notification {
"sender": notification.octopushSenderName "sender": notification.octopushSenderName
}; };
await axios.post(`https://api.octopush.com/v1/public/sms-campaign/send`, data, config) await axios.post("https://api.octopush.com/v1/public/sms-campaign/send", data, config)
return true; return true;
} catch (error) { } catch (error) {
console.log(error) console.log(error)
@ -356,30 +356,30 @@ class Notification {
} else if (notification.type === "pushbullet") { } else if (notification.type === "pushbullet") {
try { try {
let pushbulletUrl = `https://api.pushbullet.com/v2/pushes`; let pushbulletUrl = "https://api.pushbullet.com/v2/pushes";
let config = { let config = {
headers: { headers: {
'Access-Token': notification.pushbulletAccessToken, "Access-Token": notification.pushbulletAccessToken,
'Content-Type': 'application/json' "Content-Type": "application/json"
} }
}; };
if (heartbeatJSON == null) { if (heartbeatJSON == null) {
let testdata = { let testdata = {
"type": "note", "type": "note",
"title": "Uptime Kuma Alert", "title": "Uptime Kuma Alert",
"body": "Testing Successful.", "body": "Testing Successful.",
} }
await axios.post(pushbulletUrl, testdata, config) await axios.post(pushbulletUrl, testdata, config)
} else if (heartbeatJSON["status"] == 0) { } else if (heartbeatJSON["status"] == 0) {
let downdata = { let downdata = {
"type": "note", "type": "note",
"title": "UptimeKuma Alert:" + monitorJSON["name"], "title": "UptimeKuma Alert:" + monitorJSON["name"],
"body": "[🔴 Down]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], "body": "[🔴 Down]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"],
} }
await axios.post(pushbulletUrl, downdata, config) await axios.post(pushbulletUrl, downdata, config)
} else if (heartbeatJSON["status"] == 1) { } else if (heartbeatJSON["status"] == 1) {
let updata = { let updata = {
"type": "note", "type": "note",
"title": "UptimeKuma Alert:" + monitorJSON["name"], "title": "UptimeKuma Alert:" + monitorJSON["name"],
"body": "[✅ Up]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], "body": "[✅ Up]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"],
} }
@ -432,15 +432,21 @@ class Notification {
static async smtp(notification, msg) { static async smtp(notification, msg) {
let transporter = nodemailer.createTransport({ const config = {
host: notification.smtpHost, host: notification.smtpHost,
port: notification.smtpPort, port: notification.smtpPort,
secure: notification.smtpSecure, secure: notification.smtpSecure,
auth: { };
// Should fix the issue in https://github.com/louislam/uptime-kuma/issues/26#issuecomment-896373904
if (notification.smtpUsername || notification.smtpPassword) {
config.auth = {
user: notification.smtpUsername, user: notification.smtpUsername,
pass: notification.smtpPassword, pass: notification.smtpPassword,
}, };
}); }
let transporter = nodemailer.createTransport(config);
// send mail with defined transport object // send mail with defined transport object
await transporter.sendMail({ await transporter.sendMail({