Added email to console for easy debugging.

This commit is contained in:
Ylian Saint-Hilaire 2022-09-02 15:27:07 -07:00
parent 2045ebc110
commit 9738848dc5
2 changed files with 59 additions and 43 deletions

View File

@ -3878,7 +3878,7 @@ function mainStart() {
if (domainCount == 0) { allsspi = false; }
for (var i in config.domains) {
if (i.startsWith('_')) continue;
if ((config.domains[i].smtp != null) || (config.domains[i].sendmail != null)) { nodemailer = true; }
if (((config.domains[i].smtp != null) && (config.domains[i].smtp.name != 'console')) || (config.domains[i].sendmail != null)) { nodemailer = true; }
if (config.domains[i].sendgrid != null) { sendgrid = true; }
if (config.domains[i].yubikey != null) { yubikey = true; }
if (config.domains[i].auth == 'ldap') { ldap = true; }
@ -3921,7 +3921,7 @@ function mainStart() {
if (config.settings.plugins != null) { modules.push('semver'); } // Required for version compat testing and update checks
if ((config.settings.plugins != null) && (config.settings.plugins.proxy != null)) { modules.push('https-proxy-agent'); } // Required for HTTP/HTTPS proxy support
else if (config.settings.xmongodb != null) { modules.push('mongojs'); } // Add MongoJS, old driver.
if (nodemailer || (config.smtp != null) || (config.sendmail != null)) { modules.push('nodemailer'); } // Add SMTP support
if (nodemailer || ((config.smtp != null) && (config.smtp.name != 'console')) || (config.sendmail != null)) { modules.push('nodemailer'); } // Add SMTP support
if (sendgrid || (config.sendgrid != null)) { modules.push('@sendgrid/mail'); } // Add SendGrid support
if (args.translate) { modules.push('jsdom'); modules.push('esprima'); modules.push('minify-js'); modules.push('html-minifier'); } // Translation support
if (typeof config.settings.crowdsec == 'object') { modules.push('@crowdsec/express-bouncer'); } // Add CrowdSec bounser module (https://www.npmjs.com/package/@crowdsec/express-bouncer)

View File

@ -43,6 +43,10 @@ module.exports.CreateMeshMail = function (parent, domain) {
if (obj.config.sendgrid.verifyemail == true) { obj.verifyemail = true; }
} else if (obj.config.smtp != null) {
// Setup SMTP mail server
if (obj.config.smtp.name == 'console') {
// This is for debugging, the mails will be displayed on the console
obj.smtpServer = 'console';
} else {
const nodemailer = require('nodemailer');
var options = { name: obj.config.smtp.name, host: obj.config.smtp.host, secure: (obj.config.smtp.tls == true), tls: {} };
//var options = { host: obj.config.smtp.host, secure: (obj.config.smtp.tls == true), tls: { secureProtocol: 'SSLv23_method', ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE, rejectUnauthorized: false } };
@ -63,6 +67,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
if (obj.config.smtp.verifyemail == true) { obj.verifyemail = true; }
obj.smtpServer = nodemailer.createTransport(options);
}
} else if (obj.config.sendmail != null) {
// Setup Sendmail
const nodemailer = require('nodemailer');
@ -440,8 +445,18 @@ module.exports.CreateMeshMail = function (parent, domain) {
}
});
} else if (obj.smtpServer != null) {
// SMTP send
parent.debug('email', 'SMTP sending mail to ' + mailToSend.to + '.');
if (obj.smtpServer == 'console') {
// Display the email on the console, this is for easy debugging
if (mailToSend.from == null) { delete mailToSend.from; }
if (mailToSend.html == null) { delete mailToSend.html; }
console.log('Email', mailToSend);
obj.sendingMail = false;
obj.pendingMails.shift();
obj.retry = 0;
sendNextMail();
} else {
// SMTP send
obj.smtpServer.sendMail(mailToSend, function (err, info) {
parent.debug('email', 'SMTP response: ' + JSON.stringify(err) + ', ' + JSON.stringify(info));
obj.sendingMail = false;
@ -469,10 +484,11 @@ module.exports.CreateMeshMail = function (parent, domain) {
});
}
}
}
// Send out the next mail in the pending list
obj.verify = function () {
if (obj.smtpServer == null) return;
if ((obj.smtpServer == null) || (obj.smtpServer == 'console')) return;
obj.smtpServer.verify(function (err, info) {
if (err == null) {
if (obj.config.smtp.host == 'gmail') {