-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
exports.up = function (knex) { | ||
return knex.schema | ||
.alterTable("monitor", function (table) { | ||
table.string("smtp_security").defaultTo(null); | ||
}); | ||
}; | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.alterTable("monitor", function (table) { | ||
table.dropColumn("smtp_security"); | ||
}); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const { MonitorType } = require("./monitor-type"); | ||
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"; | ||
} | ||
|
||
/** | ||
* @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"; | ||
} | ||
|
||
/** | ||
* @param {*} smtpSecurity the user's SMTP security setting | ||
* @returns {boolean} True if this should always test STARTTLS | ||
*/ | ||
isRequireTLS(smtpSecurity) { | ||
return smtpSecurity === "starttls"; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async check(monitor, heartbeat, _server) { | ||
let options = { | ||
port: monitor.port || 25, | ||
host: monitor.hostname, | ||
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"; | ||
} catch (e) { | ||
throw new Error(`SMTP connection doesn't verify: ${e}`); | ||
} finally { | ||
transporter.close(); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
SMTPMonitorType, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters