More SMTP debugging messages, updated MeshCentral Router.

Ylian Saint-Hilaire committed Apr 5, 2020 at 12:44 UTC b992af2f9d8b577cffa47e3d33ab5fadcc9c673f
2 files changed +49 -10
agents/MeshCentralRouter.exe
Binary files a/agents/MeshCentralRouter.exe and b/agents/MeshCentralRouter.exe differ
meshmail.js
+49 -10
@@ -42,6 +42,7 @@ module.exports.CreateMeshMail = function (parent) {
42
43 // Get the correct mail template object
44 function getTemplate(name, domain, lang) {
45 + parent.debug('email', 'Getting mail template for: ' + name + ', lang: ' + lang);
46 if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given.
47
48 var r = {}, emailsPath = null;
@@ -63,7 +64,7 @@ module.exports.CreateMeshMail = function (parent) {
64 }
65
66 // Get the english email
66 - if (htmlfile == null) {
67 + if ((htmlfile == null) || (txtfile == null)) {
68 var pathHtml = obj.parent.path.join(emailsPath, name + '.html');
69 var pathTxt = obj.parent.path.join(emailsPath, name + '.txt');
70 if (obj.parent.fs.existsSync(pathHtml) && obj.parent.fs.existsSync(pathTxt)) {
@@ -152,8 +153,16 @@ module.exports.CreateMeshMail = function (parent) {
153 if (checked) {
154 parent.debug('email', "Sending login token to " + email);
155
156 + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
157 + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
158 + return;
159 + }
160 +
161 var template = getTemplate('account-login', domain, language);
156 - 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.
162 + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
163 + parent.debug('email', "Error: Failed to get mail template."); // Not email template found
164 + return;
165 + }
166
167 // Set all the options.
168 var options = { email: email, servername: domain.title ? domain.title : 'MeshCentral', token: token };
@@ -171,8 +180,16 @@ module.exports.CreateMeshMail = function (parent) {
180 if (checked) {
181 parent.debug('email', "Sending account invitation to " + email);
182
183 + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
184 + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
185 + return;
186 + }
187 +
188 var template = getTemplate('account-invite', domain, language);
175 - 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.
189 + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
190 + parent.debug('email', "Error: Failed to get mail template."); // Not email template found
191 + return;
192 + }
193
194 // Set all the options.
195 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) {
207 if (checked) {
208 parent.debug('email', "Sending email verification to " + email);
209
210 + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
211 + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
212 + return;
213 + }
214 +
215 var template = getTemplate('account-check', domain, language);
194 - 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.
216 + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
217 + parent.debug('email', "Error: Failed to get mail template."); // Not email template found
218 + return;
219 + }
220
221 // Set all the options.
222 var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
@@ -210,8 +235,16 @@ module.exports.CreateMeshMail = function (parent) {
235 if (checked) {
236 parent.debug('email', "Sending account password reset to " + email);
237
238 + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
239 + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
240 + return;
241 + }
242 +
243 var template = getTemplate('account-reset', domain, language);
214 - 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.
244 + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
245 + parent.debug('email', "Error: Failed to get mail template."); // Not email template found
246 + return;
247 + }
248
249 // Set all the options.
250 var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' };
@@ -229,10 +262,16 @@ module.exports.CreateMeshMail = function (parent) {
262 obj.checkEmail(email, function (checked) {
263 if (checked) {
264 parent.debug('email', "Sending agent install invitation to " + email);
265 +
266 + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
267 + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible.
268 + return;
269 + }
270 +
271 var template = getTemplate('mesh-invite', domain, language);
233 - if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) {
234 - parent.debug('email', "Failed to get email template for " + email);
235 - return; // If the server name is not set, don't validate the email address.
272 + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) {
273 + parent.debug('email', "Error: Failed to get mail template."); // Not email template found
274 + return;
275 }
276
277 // 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) {
295
296 var mailToSend = obj.pendingMails[0];
297 obj.sendingMail = true;
259 - //console.log('SMTP sending mail to ' + mailToSend.to + '.');
298 + parent.debug('email', 'SMTP sending mail to ' + mailToSend.to + '.');
299 obj.smtpServer.sendMail(mailToSend, function (err, info) {
261 - //console.log(JSON.stringify(err), JSON.stringify(info));
300 + parent.debug('email', 'SMTP response: ' + JSON.stringify(err) + ', ' + JSON.stringify(info));
301 obj.sendingMail = false;
302 if (err == null) {
303 obj.pendingMails.shift();