Fixed SendGrid support.

This commit is contained in:
Ylian Saint-Hilaire 2021-01-24 22:15:12 -08:00
parent a885664a41
commit aa01c671a9
1 changed files with 17 additions and 0 deletions

View File

@ -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