Skip to content

Node.js based forum software built for the modern web

Revert "fix: update usage of emailer.send to not catch (as errors are no longer thrown), email error throttler"

Julian Lam165a1d8b7691
diff --git a/src/emailer.js b/src/emailer.js
index 107cb7e526..25e598776c 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -343,10 +343,6 @@ Emailer.sendToEmail = async (template, email, language, params) => {
return true;
} catch (err) {
- if (Emailer._emailFailThrottle) {
- return false;
- }
-
if (err.code === 'ENOENT' && usingFallback) {
Emailer.fallbackNotFound = true;
winston.error(`[emailer/sendToEmail] ${await translator.translate('[[error:sendmail-not-found]]')}`);
@@ -354,10 +350,6 @@ Emailer.sendToEmail = async (template, email, language, params) => {
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;
}
};
diff --git a/src/notifications.js b/src/notifications.js
index fa088c9025..6c9c01f46f 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -194,6 +194,7 @@ async function pushToUids(uids, notification) {
}
body = posts.relativeToAbsolute(body, posts.urlRegex);
body = posts.relativeToAbsolute(body, posts.imgRegex);
+ let errorLogged = false;
await async.eachLimit(uids, 3, async (uid) => {
await emailer.send('notification', uid, {
path: notification.path,
@@ -203,6 +204,11 @@ async function pushToUids(uids, notification) {
body: body,
notification: notification,
showUnsubscribe: true,
+ }).catch((err) => {
+ if (!errorLogged) {
+ winston.error(`[emailer.send] ${err.stack}`);
+ errorLogged = true;
+ }
});
});
}
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index 6648d1974a..55a9a26d87 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -90,7 +90,7 @@ SocketUser.reset.commit = async function (socket, data) {
username: username,
date: parsedDate,
subject: '[[email:reset.notify.subject]]',
- });
+ }).catch(err => winston.error(`[emailer.send] ${err.stack}`));
};
SocketUser.isFollowing = async function (socket, data) {
diff --git a/src/user/approval.js b/src/user/approval.js
index 029e32715a..24e84fba64 100644
--- a/src/user/approval.js
+++ b/src/user/approval.js
@@ -79,7 +79,7 @@ module.exports = function (User) {
subject: `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]`,
template: 'registration_accepted',
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 counter = await db.incrObjectField('registration:queue:approval:times', 'counter');
await db.setObjectField('registration:queue:approval:times', 'average', total / counter);
diff --git a/src/user/bans.js b/src/user/bans.js
index 3dcf8b3ce3..8a7352d29e 100644
--- a/src/user/bans.js
+++ b/src/user/bans.js
@@ -58,7 +58,7 @@ module.exports = function (User) {
until: until ? (new Date(until)).toUTCString().replace(/,/g, '\\,') : false,
reason: reason,
};
- await emailer.send('banned', uid, data);
+ await emailer.send('banned', uid, data).catch(err => winston.error(`[emailer.send] ${err.stack}`));
return banData;
};
diff --git a/src/user/digest.js b/src/user/digest.js
index ecb55c51a4..5a23b0fd8f 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -103,6 +103,7 @@ Digest.send = async function (data) {
if (!data || !data.subscribers || !data.subscribers.length) {
return emailsSent;
}
+ let errorLogged = false;
await batch.processArray(data.subscribers, async (uids) => {
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']));
@@ -141,6 +142,11 @@ Digest.send = async function (data) {
popularTopics: topics.popular,
interval: data.interval,
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') {
diff --git a/src/user/reset.js b/src/user/reset.js
index ad3ef60530..b8a77a4d08 100644
--- a/src/user/reset.js
+++ b/src/user/reset.js
@@ -59,7 +59,7 @@ UserReset.send = async function (email) {
subject: '[[email:password-reset-requested]]',
template: 'reset',
uid: uid,
- });
+ }).catch(err => winston.error(`[emailer.send] ${err.stack}`));
return code;
};