diff --git a/server/monitor-types/smtp.js b/server/monitor-types/smtp.js index 6683b83ec..3026dc2df 100644 --- a/server/monitor-types/smtp.js +++ b/server/monitor-types/smtp.js @@ -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, -}; \ No newline at end of file +};