mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: update usage of emailer.send to not catch (as errors are no longer thrown), email error throttler
This commit is contained in:
@@ -343,6 +343,10 @@ Emailer.sendToEmail = async (template, email, language, params) => {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (Emailer._emailFailThrottle) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (err.code === 'ENOENT' && usingFallback) {
|
if (err.code === 'ENOENT' && usingFallback) {
|
||||||
Emailer.fallbackNotFound = true;
|
Emailer.fallbackNotFound = true;
|
||||||
winston.error(`[emailer/sendToEmail] ${await translator.translate('[[error:sendmail-not-found]]')}`);
|
winston.error(`[emailer/sendToEmail] ${await translator.translate('[[error:sendmail-not-found]]')}`);
|
||||||
@@ -350,6 +354,10 @@ Emailer.sendToEmail = async (template, email, language, params) => {
|
|||||||
winston.error(`[emailer/sendToEmail] ${err.message || err.code || 'Unknown error while sending email.'}`);
|
winston.error(`[emailer/sendToEmail] ${err.message || err.code || 'Unknown error while sending email.'}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Emailer._emailFailThrottle = setTimeout(() => {
|
||||||
|
delete Emailer._emailFailThrottle;
|
||||||
|
}, 1000 * 60 * 5); // 5 minutes
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ async function pushToUids(uids, notification) {
|
|||||||
}
|
}
|
||||||
body = posts.relativeToAbsolute(body, posts.urlRegex);
|
body = posts.relativeToAbsolute(body, posts.urlRegex);
|
||||||
body = posts.relativeToAbsolute(body, posts.imgRegex);
|
body = posts.relativeToAbsolute(body, posts.imgRegex);
|
||||||
let errorLogged = false;
|
|
||||||
await async.eachLimit(uids, 3, async (uid) => {
|
await async.eachLimit(uids, 3, async (uid) => {
|
||||||
await emailer.send('notification', uid, {
|
await emailer.send('notification', uid, {
|
||||||
path: notification.path,
|
path: notification.path,
|
||||||
@@ -204,11 +203,6 @@ async function pushToUids(uids, notification) {
|
|||||||
body: body,
|
body: body,
|
||||||
notification: notification,
|
notification: notification,
|
||||||
showUnsubscribe: true,
|
showUnsubscribe: true,
|
||||||
}).catch((err) => {
|
|
||||||
if (!errorLogged) {
|
|
||||||
winston.error(`[emailer.send] ${err.stack}`);
|
|
||||||
errorLogged = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ SocketUser.reset.commit = async function (socket, data) {
|
|||||||
username: username,
|
username: username,
|
||||||
date: parsedDate,
|
date: parsedDate,
|
||||||
subject: '[[email:reset.notify.subject]]',
|
subject: '[[email:reset.notify.subject]]',
|
||||||
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.isFollowing = async function (socket, data) {
|
SocketUser.isFollowing = async function (socket, data) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ module.exports = function (User) {
|
|||||||
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
|
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
|
||||||
template: 'registration_accepted',
|
template: 'registration_accepted',
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
|
});
|
||||||
const total = await db.incrObjectFieldBy('registration:queue:approval:times', 'totalTime', Math.floor((Date.now() - creation_time) / 60000));
|
const total = await db.incrObjectFieldBy('registration:queue:approval:times', 'totalTime', Math.floor((Date.now() - creation_time) / 60000));
|
||||||
const counter = await db.incrObjectField('registration:queue:approval:times', 'counter');
|
const counter = await db.incrObjectField('registration:queue:approval:times', 'counter');
|
||||||
await db.setObjectField('registration:queue:approval:times', 'average', total / counter);
|
await db.setObjectField('registration:queue:approval:times', 'average', total / counter);
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ module.exports = function (User) {
|
|||||||
until: until ? (new Date(until)).toUTCString().replace(/,/g, '\\,') : false,
|
until: until ? (new Date(until)).toUTCString().replace(/,/g, '\\,') : false,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
};
|
};
|
||||||
await emailer.send('banned', uid, data).catch(err => winston.error(`[emailer.send] ${err.stack}`));
|
await emailer.send('banned', uid, data);
|
||||||
|
|
||||||
return banData;
|
return banData;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ Digest.send = async function (data) {
|
|||||||
if (!data || !data.subscribers || !data.subscribers.length) {
|
if (!data || !data.subscribers || !data.subscribers.length) {
|
||||||
return emailsSent;
|
return emailsSent;
|
||||||
}
|
}
|
||||||
let errorLogged = false;
|
|
||||||
await batch.processArray(data.subscribers, async (uids) => {
|
await batch.processArray(data.subscribers, async (uids) => {
|
||||||
let userData = await user.getUsersFields(uids, ['uid', 'email', 'email:confirmed', 'username', 'userslug', 'lastonline']);
|
let userData = await user.getUsersFields(uids, ['uid', 'email', 'email:confirmed', 'username', 'userslug', 'lastonline']);
|
||||||
userData = userData.filter(u => u && u.email && (meta.config.includeUnverifiedEmails || u['email:confirmed']));
|
userData = userData.filter(u => u && u.email && (meta.config.includeUnverifiedEmails || u['email:confirmed']));
|
||||||
@@ -142,11 +141,6 @@ Digest.send = async function (data) {
|
|||||||
popularTopics: topics.popular,
|
popularTopics: topics.popular,
|
||||||
interval: data.interval,
|
interval: data.interval,
|
||||||
showUnsubscribe: true,
|
showUnsubscribe: true,
|
||||||
}).catch((err) => {
|
|
||||||
if (!errorLogged) {
|
|
||||||
winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`);
|
|
||||||
errorLogged = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
if (data.interval !== 'alltime') {
|
if (data.interval !== 'alltime') {
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ UserReset.send = async function (email) {
|
|||||||
subject: '[[email:password-reset-requested]]',
|
subject: '[[email:password-reset-requested]]',
|
||||||
template: 'reset',
|
template: 'reset',
|
||||||
uid: uid,
|
uid: uid,
|
||||||
}).catch(err => winston.error(`[emailer.send] ${err.stack}`));
|
});
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user