This commit is contained in:
Brad Koehn 2025-01-01 14:59:53 -06:00
parent 16edd5932e
commit ab0ba80db7
No known key found for this signature in database

View file

@ -1,22 +1,34 @@
const { MonitorType } = require("./monitor-type");
const { UP, log, evaluateJsonQuery } = require("../../src/util");
const { UP } = require("../../src/util");
const nodemailer = require("nodemailer");
class SMTPMonitorType extends MonitorType {
name = "smtp";
/**
* @param {*} smtpSecurity the user's SMTP security setting
* @returns {boolean} True if this should test SMTPS
*/
isSMTPS(smtpSecurity) {
return smtpSecurity === 'secure';
return smtpSecurity === "secure";
}
/**
* @param {*} smtpSecurity the user's SMTP security setting
* @returns {boolean} True if this should not attempt STARTTLS, even if it is available
*/
isIgnoreTLS(smtpSecurity) {
return smtpSecurity === 'nostarttls';
return smtpSecurity === "nostarttls";
}
/**
* @param {*} smtpSecurity the user's SMTP security setting
* @returns {boolean} True if this should always test STARTTLS
*/
isRequireTLS(smtpSecurity) {
return smtpSecurity === 'starttls';
return smtpSecurity === "starttls";
}
/**
* @inheritdoc
*/
@ -27,13 +39,13 @@ class SMTPMonitorType extends MonitorType {
secure: this.isSMTPS(monitor.smtpSecurity), // use SMTPS (not STARTTLS)
ignoreTLS: this.isIgnoreTLS(monitor.smtpSecurity), // don't use STARTTLS even if it's available
requireTLS: this.isRequireTLS(monitor.smtpSecurity), // use STARTTLS or fail
}
};
let transporter = nodemailer.createTransport(options);
try {
await transporter.verify();
heartbeat.status = UP;
heartbeat.msg = `SMTP connection verifies successfully`;
heartbeat.msg = "SMTP connection verifies successfully";
} catch (e) {
throw new Error(`SMTP connection doesn't verify: ${e}`);
} finally {
@ -44,4 +56,4 @@ class SMTPMonitorType extends MonitorType {
module.exports = {
SMTPMonitorType,
};
};