1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Added support for help request emails (#4489)

This commit is contained in:
Ylian Saint-Hilaire 2022-09-02 17:03:38 -07:00
parent 9738848dc5
commit 4e86b319f7
47 changed files with 2911 additions and 2155 deletions

View file

@ -381,8 +381,8 @@ module.exports.CreateMeshMail = function (parent, domain) {
}
// Set all the template replacement options and generate the final email text (both in txt and html formats).
var optionsHtml = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral', header: true, footer: false };
var optionsTxt = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral', header: true, footer: false };
const optionsHtml = { username: EscapeHtml(username), email: EscapeHtml(email), servername: EscapeHtml(domain.title ? domain.title : 'MeshCentral'), header: true, footer: false };
const optionsTxt = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral', header: true, footer: false };
if ((connections == null) || (connections.length == 0)) {
optionsHtml.connections = false;
optionsTxt.connections = false;
@ -410,6 +410,39 @@ module.exports.CreateMeshMail = function (parent, domain) {
});
};
// Send device help request notification mail
obj.sendDeviceHelpMail = function (domain, username, email, devicename, nodeid, helpusername, helprequest, language) {
obj.checkEmail(email, function (checked) {
if (checked) {
parent.debug('email', "Sending device help notification to " + email);
if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
return;
}
var template = getTemplate('device-help', domain, language);
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
parent.debug('email', "Error: Failed to get mail template."); // No email template found
return;
}
// Set all the template replacement options and generate the final email text (both in txt and html formats).
const optionsHtml = { devicename: EscapeHtml(devicename), helpusername: EscapeHtml(helpusername), helprequest: EscapeHtml(helprequest), nodeid: nodeid.split('/')[2], servername: EscapeHtml(domain.title ? domain.title : 'MeshCentral') };
const optionsTxt = { devicename: devicename, helpusername: helpusername, helprequest: helprequest, nodeid: nodeid.split('/')[2], servername: domain.title ? domain.title : 'MeshCentral' };
// Get from field
var from = null;
if (obj.config.sendgrid && (typeof obj.config.sendgrid.from == 'string')) { from = obj.config.sendgrid.from; }
else if (obj.config.smtp && (typeof obj.config.smtp.from == 'string')) { from = obj.config.smtp.from; }
// Send the email
obj.pendingMails.push({ to: email, from: from, subject: mailReplacements(template.htmlSubject, domain, optionsTxt), text: mailReplacements(template.txt, domain, optionsTxt), html: mailReplacements(template.html, domain, optionsHtml) });
sendNextMail();
}
});
};
// Send out the next mail in the pending list
function sendNextMail() {
if ((obj.sendingMail == true) || (obj.pendingMails.length == 0)) { return; }