mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-15 13:54:45 +00:00
Some checks are pending
Auto Test / auto-test (18, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, windows-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (20, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, windows-latest) (push) Blocked by required conditions
Auto Test / armv7-simple-test (18, ARMv7) (push) Waiting to run
Auto Test / armv7-simple-test (20, ARMv7) (push) Waiting to run
Auto Test / check-linters (push) Waiting to run
Auto Test / e2e-test (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
validate / json-yaml-validate (push) Waiting to run
validate / validate (push) Waiting to run
77 lines
2.7 KiB
JavaScript
77 lines
2.7 KiB
JavaScript
const nodemailer = require("nodemailer");
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
class SMTP extends NotificationProvider {
|
|
name = "smtp";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
const okMsg = "Sent Successfully.";
|
|
|
|
const config = {
|
|
host: notification.smtpHost,
|
|
port: notification.smtpPort,
|
|
secure: notification.smtpSecure,
|
|
tls: {
|
|
rejectUnauthorized: !notification.smtpIgnoreTLSError || false,
|
|
}
|
|
};
|
|
|
|
// Fix #1129
|
|
if (notification.smtpDkimDomain) {
|
|
config.dkim = {
|
|
domainName: notification.smtpDkimDomain,
|
|
keySelector: notification.smtpDkimKeySelector,
|
|
privateKey: notification.smtpDkimPrivateKey,
|
|
hashAlgo: notification.smtpDkimHashAlgo,
|
|
headerFieldNames: notification.smtpDkimheaderFieldNames,
|
|
skipFields: notification.smtpDkimskipFields,
|
|
};
|
|
}
|
|
|
|
// 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,
|
|
};
|
|
}
|
|
|
|
// default values in case the user does not want to template
|
|
let subject = msg;
|
|
let body = msg;
|
|
if (heartbeatJSON) {
|
|
body = `${msg}\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
|
}
|
|
// subject and body are templated
|
|
if ((monitorJSON && heartbeatJSON) || msg.endsWith("Testing")) {
|
|
// cannot end with whitespace as this often raises spam scores
|
|
const customSubject = notification.customSubject?.trim() || "";
|
|
const customBody = notification.customBody?.trim() || "";
|
|
|
|
if (customSubject !== "") {
|
|
subject = await this.renderTemplate(customSubject, msg, monitorJSON, heartbeatJSON);
|
|
}
|
|
if (customBody !== "") {
|
|
body = await this.renderTemplate(customBody, msg, monitorJSON, heartbeatJSON);
|
|
}
|
|
}
|
|
|
|
// send mail with defined transport object
|
|
let transporter = nodemailer.createTransport(config);
|
|
await transporter.sendMail({
|
|
from: notification.smtpFrom,
|
|
cc: notification.smtpCC,
|
|
bcc: notification.smtpBCC,
|
|
to: notification.smtpTo,
|
|
subject: subject,
|
|
text: body,
|
|
});
|
|
|
|
return okMsg;
|
|
}
|
|
}
|
|
|
|
module.exports = SMTP;
|