Node.js based forum software built for the modern web
fix: closes #13641, log test email sending errors server side
Barış Soner Uşaklıb3ffa00789f1
diff --git a/src/socket.io/admin/email.js b/src/socket.io/admin/email.jsindex ed5bce7a60..b2a160b1f3 100644--- a/src/socket.io/admin/email.js+++ b/src/socket.io/admin/email.js@@ -1,5 +1,7 @@'use strict';+const winston = require('winston');+const meta = require('../../meta');const userDigest = require('../../user/digest');const userEmail = require('../../user/email');@@ -14,55 +16,59 @@ Email.test = async function (socket, data) {...(data.payload || {}),subject: '[[email:test-email.subject]]',};+ try {+ switch (data.template) {+ case 'digest':+ await userDigest.execute({+ interval: 'month',+ subscribers: [socket.uid],+ });+ break;- switch (data.template) {- case 'digest':- await userDigest.execute({- interval: 'month',- subscribers: [socket.uid],- });- break;+ case 'banned':+ Object.assign(payload, {+ username: 'test-user',+ until: utils.toISOString(Date.now()),+ reason: 'Test Reason',+ });+ await emailer.send(data.template, socket.uid, payload);+ break;- case 'banned':- Object.assign(payload, {- username: 'test-user',- until: utils.toISOString(Date.now()),- reason: 'Test Reason',- });- await emailer.send(data.template, socket.uid, payload);- break;+ case 'verify-email':+ case 'welcome':+ await userEmail.sendValidationEmail(socket.uid, {+ force: 1,+ template: data.template,+ subject: data.template === 'welcome' ? `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]` : undefined,+ });+ break;- case 'verify-email':- case 'welcome':- await userEmail.sendValidationEmail(socket.uid, {- force: 1,- template: data.template,- subject: data.template === 'welcome' ? `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]` : undefined,- });- break;+ case 'notification': {+ const notification = await notifications.create({+ type: 'test',+ bodyShort: '[[email:notif.test.short]]',+ bodyLong: '[[email:notif.test.long]]',+ nid: `uid:${socket.uid}:test`,+ path: '/',+ from: socket.uid,+ });+ await emailer.send('notification', socket.uid, {+ path: notification.path,+ subject: utils.stripHTMLTags(notification.subject || '[[notifications:new-notification]]'),+ intro: utils.stripHTMLTags(notification.bodyShort),+ body: notification.bodyLong || '',+ notification,+ showUnsubscribe: true,+ });+ break;+ }- case 'notification': {- const notification = await notifications.create({- type: 'test',- bodyShort: '[[email:notif.test.short]]',- bodyLong: '[[email:notif.test.long]]',- nid: `uid:${socket.uid}:test`,- path: '/',- from: socket.uid,- });- await emailer.send('notification', socket.uid, {- path: notification.path,- subject: utils.stripHTMLTags(notification.subject || '[[notifications:new-notification]]'),- intro: utils.stripHTMLTags(notification.bodyShort),- body: notification.bodyLong || '',- notification,- showUnsubscribe: true,- });- break;+ default:+ await emailer.send(data.template, socket.uid, payload);+ break;}-- default:- await emailer.send(data.template, socket.uid, payload);- break;+ } catch (err) {+ winston.error(err.stack);+ throw err;}};