2021-09-07 07:42:46 -07:00
|
|
|
const nodemailer = require("nodemailer");
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
|
|
|
|
class SMTP extends NotificationProvider {
|
|
|
|
|
|
|
|
name = "smtp";
|
|
|
|
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
host: notification.smtpHost,
|
|
|
|
port: notification.smtpPort,
|
|
|
|
secure: notification.smtpSecure,
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
pass: notification.smtpPassword,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let transporter = nodemailer.createTransport(config);
|
|
|
|
|
|
|
|
let bodyTextContent = msg;
|
|
|
|
if (heartbeatJSON) {
|
|
|
|
bodyTextContent = `${msg}\nTime (UTC): ${heartbeatJSON["time"]}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send mail with defined transport object
|
|
|
|
await transporter.sendMail({
|
2021-09-08 10:13:09 -07:00
|
|
|
from: notification.smtpFrom,
|
|
|
|
cc: notification.smtpCC,
|
|
|
|
bcc: notification.smtpBCC,
|
2021-09-07 07:42:46 -07:00
|
|
|
to: notification.smtpTo,
|
|
|
|
subject: msg,
|
|
|
|
text: bodyTextContent,
|
2021-09-08 10:13:09 -07:00
|
|
|
tls: {
|
|
|
|
rejectUnauthorized: notification.smtpIgnoreTLSError || false,
|
|
|
|
},
|
2021-09-07 07:42:46 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
return "Sent Successfully.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SMTP;
|