From aa01c671a9c2246005de32d6c446e3d4959a0994 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 24 Jan 2021 22:15:12 -0800 Subject: [PATCH] Fixed SendGrid support. --- meshmail.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/meshmail.js b/meshmail.js index 8e2d1be1..8fe8c659 100644 --- a/meshmail.js +++ b/meshmail.js @@ -342,9 +342,26 @@ module.exports.CreateMeshMail = function (parent) { obj.sendGridServer .send(mailToSend) .then(function () { + obj.sendingMail = false; parent.debug('email', 'SendGrid sending success.'); + obj.pendingMails.shift(); + obj.retry = 0; + sendNextMail(); }, function (error) { + obj.sendingMail = false; parent.debug('email', 'SendGrid sending error: ' + JSON.stringify(error)); + obj.retry++; + // Wait and try again + if (obj.retry < 3) { + setTimeout(sendNextMail, 10000); + } else { + // Failed, send the next mail + parent.debug('email', 'SendGrid server failed (Skipping): ' + JSON.stringify(err)); + console.log('SendGrid server failed (Skipping): ' + JSON.stringify(err)); + obj.pendingMails.shift(); + obj.retry = 0; + sendNextMail(); + } }); } else if (obj.smtpServer != null) { // SMTP send