Added emailDelaySeconds, so email delay can be configured.
Ylian Saint-Hilaire committed
Dec 15, 2022 at 10:19 UTC
1df35c13c46d9ab2bb0d1e16643bfa1076c353de
2 files changed
+14
-9
meshcentral-config-schema.json
+6
-7
@@ -1051,7 +1051,8 @@
1051
"properties": {
1052
"from": { "type": "string", "format": "email", "description": "Email address used in the messages from field." },
1053
"apikey": { "type": "string", "description": "The SendGrid API key." },
1054
- "verifyemail": { "type": "boolean", "default": true, "description": "When set to false, the email format and DNS MX record are not checked." }
1054
+ "verifyemail": { "type": "boolean", "default": true, "description": "When set to false, the email format and DNS MX record are not checked." },
1055
+ "emailDelaySeconds": { "type": "integer", "default": 300, "description": "Time to wait before sending a device connection/disconnection notification email. If many events occur, they will be merged into a single email."}
1056
},
1057
"required": [ "from", "apikey" ]
1058
},
@@ -1093,11 +1094,8 @@
1094
},
1095
"tlscertcheck": { "type": "boolean" },
1096
"tlsstrict": { "type": "boolean" },
1096
- "verifyemail": {
1097
- "type": "boolean",
1098
- "default": true,
1099
- "description": "When set to false, the email format and DNS MX record are not checked."
1100
- }
1097
+ "verifyemail": { "type": "boolean", "default": true, "description": "When set to false, the email format and DNS MX record are not checked." },
1098
+ "emailDelaySeconds": { "type": "integer", "default": 300, "description": "Time to wait before sending a device connection/disconnection notification email. If many events occur, they will be merged into a single email."}
1099
},
1100
"required": [ "from" ]
1101
},
@@ -1108,7 +1106,8 @@
1106
"properties": {
1107
"newline": { "type": "string", "default": "unix", "description": "Possible values are unix or windows" },
1108
"path": { "type": "string", "default": "sendmail", "description": "Path to the sendmail command" },
1111
- "args": { "type": "array", "items": { "type": "string" }, "default": null, "description": "Array or arguments to pass to sendmail" }
1109
+ "args": { "type": "array", "items": { "type": "string" }, "default": null, "description": "Array or arguments to pass to sendmail" },
1110
+ "emailDelaySeconds": { "type": "integer", "default": 300, "description": "Time to wait before sending a device connection/disconnection notification email. If many events occur, they will be merged into a single email."}
1111
}
1112
},
1113
"authStrategies": {
meshmail.js
+8
-2
@@ -26,6 +26,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
26
obj.mailCookieEncryptionKey = null;
27
obj.verifyemail = false;
28
obj.domain = domain;
29
+ obj.emailDelay = 5 * 60 * 1000; // Default of 5 minute email delay.
30
//obj.mailTemplates = {};
31
const sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
32
const constants = (obj.parent.crypto.constants ? obj.parent.crypto.constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead.
@@ -41,8 +42,10 @@ module.exports.CreateMeshMail = function (parent, domain) {
42
obj.sendGridServer = require('@sendgrid/mail');
43
obj.sendGridServer.setApiKey(obj.config.sendgrid.apikey);
44
if (obj.config.sendgrid.verifyemail == true) { obj.verifyemail = true; }
45
+ if ((typeof obj.config.sendgrid.emaildelayseconds == 'number') && (obj.config.sendgrid.emaildelayseconds > 0)) { obj.emailDelay = obj.config.sendgrid.emaildelayseconds * 1000; }
46
} else if (obj.config.smtp != null) {
47
// Setup SMTP mail server
48
+ if ((typeof obj.config.smtp.emaildelayseconds == 'number') && (obj.config.smtp.emaildelayseconds > 0)) { obj.emailDelay = obj.config.smtp.emaildelayseconds * 1000; }
49
if (obj.config.smtp.name == 'console') {
50
// This is for debugging, the mails will be displayed on the console
51
obj.smtpServer = 'console';
@@ -70,6 +73,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
73
}
74
} else if (obj.config.sendmail != null) {
75
// Setup Sendmail
76
+ if ((typeof obj.config.sendmail.emaildelayseconds == 'number') && (obj.config.sendmail.emaildelayseconds > 0)) { obj.emailDelay = obj.config.sendmail.emaildelayseconds * 1000; }
77
const nodemailer = require('nodemailer');
78
var options = { sendmail: true };
79
if (typeof obj.config.sendmail.newline == 'string') { options.newline = obj.config.sendmail.newline; }
@@ -78,6 +82,8 @@ module.exports.CreateMeshMail = function (parent, domain) {
82
obj.smtpServer = nodemailer.createTransport(options);
83
}
84
85
+ console.log('obj.emailDelay', obj.emailDelay);
86
+
87
// Get the correct mail template object
88
function getTemplate(name, domain, lang) {
89
parent.debug('email', 'Getting mail template for: ' + name + ', lang: ' + lang);
@@ -584,7 +590,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
590
// Add the user and start a timer
591
if (obj.deviceNotifications[user._id] == null) {
592
obj.deviceNotifications[user._id] = { nodes: {} };
587
- obj.deviceNotifications[user._id].timer = setTimeout(function () { sendDeviceNotifications(user._id); }, 5 * 60 * 1000); // 5 minute before email is sent
593
+ obj.deviceNotifications[user._id].timer = setTimeout(function () { sendDeviceNotifications(user._id); }, obj.emailDelay);
594
}
595
596
// Add the device
@@ -648,7 +654,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
654
// Add the user and start a timer
655
if (obj.deviceNotifications[user._id] == null) {
656
obj.deviceNotifications[user._id] = { nodes: {} };
651
- obj.deviceNotifications[user._id].timer = setTimeout(function () { sendDeviceNotifications(user._id); }, 5 * 60 * 1000); // 5 minute before email is sent
657
+ obj.deviceNotifications[user._id].timer = setTimeout(function () { sendDeviceNotifications(user._id); }, obj.emailDelay);
658
}
659
660
// Add the device