mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-23 12:43:14 -05:00
More SMTP debugging messages, updated MeshCentral Router.
This commit is contained in:
parent
f2332a14fc
commit
b992af2f9d
Binary file not shown.
59
meshmail.js
59
meshmail.js
@ -42,6 +42,7 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
|
|
||||||
// Get the correct mail template object
|
// Get the correct mail template object
|
||||||
function getTemplate(name, domain, lang) {
|
function getTemplate(name, domain, lang) {
|
||||||
|
parent.debug('email', 'Getting mail template for: ' + name + ', lang: ' + lang);
|
||||||
if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given.
|
if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given.
|
||||||
|
|
||||||
var r = {}, emailsPath = null;
|
var r = {}, emailsPath = null;
|
||||||
@ -63,7 +64,7 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the english email
|
// Get the english email
|
||||||
if (htmlfile == null) {
|
if ((htmlfile == null) || (txtfile == null)) {
|
||||||
var pathHtml = obj.parent.path.join(emailsPath, name + '.html');
|
var pathHtml = obj.parent.path.join(emailsPath, name + '.html');
|
||||||
var pathTxt = obj.parent.path.join(emailsPath, name + '.txt');
|
var pathTxt = obj.parent.path.join(emailsPath, name + '.txt');
|
||||||
if (obj.parent.fs.existsSync(pathHtml) && obj.parent.fs.existsSync(pathTxt)) {
|
if (obj.parent.fs.existsSync(pathHtml) && obj.parent.fs.existsSync(pathTxt)) {
|
||||||
@ -152,8 +153,16 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
parent.debug('email', "Sending login token to " + email);
|
parent.debug('email', "Sending login token 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('account-login', domain, language);
|
var template = getTemplate('account-login', domain, language);
|
||||||
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) return; // If the server name is not set, invitation not possible.
|
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
|
||||||
|
parent.debug('email', "Error: Failed to get mail template."); // Not email template found
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set all the options.
|
// Set all the options.
|
||||||
var options = { email: email, servername: domain.title ? domain.title : 'MeshCentral', token: token };
|
var options = { email: email, servername: domain.title ? domain.title : 'MeshCentral', token: token };
|
||||||
@ -171,8 +180,16 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
parent.debug('email', "Sending account invitation to " + email);
|
parent.debug('email', "Sending account invitation 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('account-invite', domain, language);
|
var template = getTemplate('account-invite', domain, language);
|
||||||
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) return; // If the server name is not set, invitation not possible.
|
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
|
||||||
|
parent.debug('email', "Error: Failed to get mail template."); // Not email template found
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set all the options.
|
// Set all the options.
|
||||||
var options = { username: username, accountname: accountname, email: email, servername: domain.title ? domain.title : 'MeshCentral', password: password };
|
var options = { username: username, accountname: accountname, email: email, servername: domain.title ? domain.title : 'MeshCentral', password: password };
|
||||||
@ -190,8 +207,16 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
parent.debug('email', "Sending email verification to " + email);
|
parent.debug('email', "Sending email verification 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('account-check', domain, language);
|
var template = getTemplate('account-check', domain, language);
|
||||||
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) return; // If the server name is not set, no reset possible.
|
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
|
||||||
|
parent.debug('email', "Error: Failed to get mail template."); // Not email template found
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set all the options.
|
// Set all the options.
|
||||||
var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
|
var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
|
||||||
@ -210,8 +235,16 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
parent.debug('email', "Sending account password reset to " + email);
|
parent.debug('email', "Sending account password reset 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('account-reset', domain, language);
|
var template = getTemplate('account-reset', domain, language);
|
||||||
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) return; // If the server name is not set, don't validate the email address.
|
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
|
||||||
|
parent.debug('email', "Error: Failed to get mail template."); // Not email template found
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set all the options.
|
// Set all the options.
|
||||||
var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
|
var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
|
||||||
@ -229,10 +262,16 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
obj.checkEmail(email, function (checked) {
|
obj.checkEmail(email, function (checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
parent.debug('email', "Sending agent install invitation to " + email);
|
parent.debug('email', "Sending agent install invitation 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('mesh-invite', domain, language);
|
var template = getTemplate('mesh-invite', domain, language);
|
||||||
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
|
if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
|
||||||
parent.debug('email', "Failed to get email template for " + email);
|
parent.debug('email', "Error: Failed to get mail template."); // Not email template found
|
||||||
return; // If the server name is not set, don't validate the email address.
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set all the template replacement options and generate the final email text (both in txt and html formats).
|
// Set all the template replacement options and generate the final email text (both in txt and html formats).
|
||||||
@ -256,9 +295,9 @@ module.exports.CreateMeshMail = function (parent) {
|
|||||||
|
|
||||||
var mailToSend = obj.pendingMails[0];
|
var mailToSend = obj.pendingMails[0];
|
||||||
obj.sendingMail = true;
|
obj.sendingMail = true;
|
||||||
//console.log('SMTP sending mail to ' + mailToSend.to + '.');
|
parent.debug('email', 'SMTP sending mail to ' + mailToSend.to + '.');
|
||||||
obj.smtpServer.sendMail(mailToSend, function (err, info) {
|
obj.smtpServer.sendMail(mailToSend, function (err, info) {
|
||||||
//console.log(JSON.stringify(err), JSON.stringify(info));
|
parent.debug('email', 'SMTP response: ' + JSON.stringify(err) + ', ' + JSON.stringify(info));
|
||||||
obj.sendingMail = false;
|
obj.sendingMail = false;
|
||||||
if (err == null) {
|
if (err == null) {
|
||||||
obj.pendingMails.shift();
|
obj.pendingMails.shift();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user