Client's public folder renamed to static
Regular campaign sender seems to have most of the code in place. (Not tested.)
This commit is contained in:
parent
89eabea0de
commit
63765f7222
354 changed files with 836 additions and 324 deletions
|
@ -56,6 +56,28 @@ function invalidateMailer(sendConfigurationId) {
|
|||
|
||||
|
||||
async function _sendMail(transport, mail, template) {
|
||||
let tryCount = 0;
|
||||
const trySend = (callback) => {
|
||||
tryCount++;
|
||||
transport.sendMail(mail, (err, info) => {
|
||||
if (err) {
|
||||
log.error('Mail', err);
|
||||
if (err.responseCode && err.responseCode >= 400 && err.responseCode < 500 && tryCount <= 5) {
|
||||
// temporary error, try again
|
||||
log.verbose('Mail', 'Retrying after %s sec. ...', tryCount);
|
||||
return setTimeout(trySend, tryCount * 1000);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, info);
|
||||
});
|
||||
};
|
||||
|
||||
const trySendAsync = bluebird.promisify(trySend);
|
||||
return await trySendAsync();
|
||||
}
|
||||
|
||||
async function _sendTransactionalMail(transport, mail, template) {
|
||||
if (!mail.headers) {
|
||||
mail.headers = {};
|
||||
}
|
||||
|
@ -83,28 +105,9 @@ async function _sendMail(transport, mail, template) {
|
|||
});
|
||||
}
|
||||
|
||||
let tryCount = 0;
|
||||
const trySend = (callback) => {
|
||||
tryCount++;
|
||||
transport.sendMail(mail, (err, info) => {
|
||||
if (err) {
|
||||
log.error('Mail', err);
|
||||
if (err.responseCode && err.responseCode >= 400 && err.responseCode < 500 && tryCount <= 5) {
|
||||
// temporary error, try again
|
||||
log.verbose('Mail', 'Retrying after %s sec. ...', tryCount);
|
||||
return setTimeout(trySend, tryCount * 1000);
|
||||
}
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, info);
|
||||
});
|
||||
};
|
||||
|
||||
const trySendAsync = bluebird.promisify(trySend);
|
||||
return await trySendAsync();
|
||||
return await _sendMail(transport, mail);
|
||||
}
|
||||
|
||||
|
||||
async function _createTransport(sendConfiguration) {
|
||||
const mailerSettings = sendConfiguration.mailer_settings;
|
||||
const mailerType = sendConfiguration.mailer_type;
|
||||
|
@ -117,7 +120,7 @@ async function _createTransport(sendConfiguration) {
|
|||
existingListeners = existingTransport.listeners('idle');
|
||||
existingTransport.removeAllListeners('idle');
|
||||
existingTransport.removeAllListeners('stream');
|
||||
existingTransport.checkThrottling = null;
|
||||
existingTransport.throttleWait = null;
|
||||
}
|
||||
|
||||
const logFunc = (...args) => {
|
||||
|
@ -190,7 +193,7 @@ async function _createTransport(sendConfiguration) {
|
|||
existingListeners.forEach(listener => transport.on('idle', listener));
|
||||
}
|
||||
|
||||
let checkThrottling;
|
||||
let throttleWait;
|
||||
|
||||
if (mailerType === sendConfigurations.MailerType.GENERIC_SMTP || mailerType === sendConfigurations.MailerType.ZONE_MTA) {
|
||||
let throttling = mailerSettings.throttling;
|
||||
|
@ -200,7 +203,7 @@ async function _createTransport(sendConfiguration) {
|
|||
|
||||
let lastCheck = Date.now();
|
||||
|
||||
checkThrottling = function (next) {
|
||||
throttleWait = function (next) {
|
||||
if (!throttling) {
|
||||
return next();
|
||||
}
|
||||
|
@ -218,12 +221,13 @@ async function _createTransport(sendConfiguration) {
|
|||
}
|
||||
};
|
||||
} else {
|
||||
checkThrottling = next => next();
|
||||
throttleWait = next => next();
|
||||
}
|
||||
|
||||
transport.mailer = {
|
||||
checkThrottling,
|
||||
sendMail: async (mail, template) => await _sendMail(transport, mail, template)
|
||||
throttleWait: bluebird.promisify(throttleWait),
|
||||
sendTransationalMail: async (mail, template) => await _sendTransactionalMail(transport, mail, template),
|
||||
sendMassMail: async (mail, template) => await _sendMail(transport, mail)
|
||||
};
|
||||
|
||||
transports.set(sendConfiguration.id, transport);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue