Added Sendmail support, #3299

This commit is contained in:
Ylian Saint-Hilaire 2021-11-25 10:34:21 -08:00
parent 725f9923e7
commit 58f611ce72
4 changed files with 24 additions and 1 deletions

View File

@ -751,6 +751,16 @@
},
"required": [ "host", "port", "from", "tls" ]
},
"sendmail": {
"title" : "Send email using the sendmail command",
"description": "Makes MeshCentral send emails using the Unix sendmail command. Allows MeshCentral to send email messages for 2FA or user notification.",
"type": "object",
"properties": {
"newline": { "type": "string", "default": "unix", "description": "Possible values are unix or windows" },
"path": { "type": "string", "default": "sendmail", "description": "Path to the sendmail command" },
"args": { "type": "array", "items": { "type": "string" }, "default": null, "description": "Array or arguments to pass to sendmail" }
}
},
"authStrategies": {
"type": "object",
"additionalProperties": false,

View File

@ -735,7 +735,7 @@ function CreateMeshCentralServer(config, args) {
}
// Check top level configuration for any unreconized values
if (config) { for (var i in config) { if ((typeof i == 'string') && (i.length > 0) && (i[0] != '_') && (['settings', 'domaindefaults', 'domains', 'configfiles', 'smtp', 'letsencrypt', 'peers', 'sms', 'sendgrid', 'firebase', 'firebaserelay', '$schema'].indexOf(i) == -1)) { addServerWarning('Unrecognized configuration option \"' + i + '\".', 3, [ i ]); } } }
if (config) { for (var i in config) { if ((typeof i == 'string') && (i.length > 0) && (i[0] != '_') && (['settings', 'domaindefaults', 'domains', 'configfiles', 'smtp', 'letsencrypt', 'peers', 'sms', 'sendgrid', 'sendmail', 'firebase', 'firebaserelay', '$schema'].indexOf(i) == -1)) { addServerWarning('Unrecognized configuration option \"' + i + '\".', 3, [ i ]); } } }
if (typeof obj.args.userallowedip == 'string') { if (obj.args.userallowedip == '') { config.settings.userallowedip = obj.args.userallowedip = null; } else { config.settings.userallowedip = obj.args.userallowedip = obj.args.userallowedip.split(','); } }
if (typeof obj.args.userblockedip == 'string') { if (obj.args.userblockedip == '') { config.settings.userblockedip = obj.args.userblockedip = null; } else { config.settings.userblockedip = obj.args.userblockedip = obj.args.userblockedip.split(','); } }

View File

@ -52,6 +52,14 @@ module.exports.CreateMeshMail = function (parent, domain) {
if ((obj.config.smtp.user != null) && (obj.config.smtp.pass != null)) { options.auth = { user: obj.config.smtp.user, pass: obj.config.smtp.pass }; }
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');
var options = { sendmail: true };
if (typeof obj.config.smtp.newline == 'string') { options.newline = obj.config.smtp.newline; }
if (typeof obj.config.smtp.path == 'string') { options.path = obj.config.smtp.path; }
if (Array.isArray(obj.config.smtp.args)) { options.args = obj.config.smtp.args; }
obj.smtpServer = nodemailer.createTransport(options);
}
// Get the correct mail template object

View File

@ -467,6 +467,11 @@
"from": "myemail@myserver.com",
"apikey": "***********"
},
"_sendmail": {
"newline": "unix",
"path": "/usr/sbin/sendmail",
"_args": [ "-f", "foo@example.com" ]
},
"_sms": {
"provider": "twilio",
"sid": "ACxxxxxxxxx",