fix: email testing and settings change from ACP

- changing email SMTP settings wouldn't apply the first time
- "Send Test Email" now will report emailer errors in most cases
This commit is contained in:
Peter Jaszkowiak
2020-12-05 14:25:14 -07:00
committed by Julian Lam
parent 713f029dc8
commit 2be396ff6e
16 changed files with 114 additions and 85 deletions

View File

@@ -1,25 +1,24 @@
'use strict';
const async = require('async');
const userDigest = require('../../user/digest');
const userEmail = require('../../user/email');
const notifications = require('../../notifications');
const emailer = require('../../emailer');
const utils = require('../../../public/src/utils');
const utils = require('../../utils');
const Email = module.exports;
Email.test = function (socket, data, callback) {
Email.test = async function (socket, data) {
const payload = {
subject: '[[email:test-email.subject]]',
};
switch (data.template) {
case 'digest':
userDigest.execute({
await userDigest.execute({
interval: 'alltime',
subscribers: [socket.uid],
}, callback);
});
break;
case 'banned':
@@ -28,42 +27,36 @@ Email.test = function (socket, data, callback) {
until: utils.toISOString(Date.now()),
reason: 'Test Reason',
});
emailer.send(data.template, socket.uid, payload, callback);
await emailer.send(data.template, socket.uid, payload);
break;
case 'welcome':
userEmail.sendValidationEmail(socket.uid, {
await userEmail.sendValidationEmail(socket.uid, {
force: 1,
}, callback);
});
break;
case 'notification':
async.waterfall([
function (next) {
notifications.create({
type: 'test',
bodyShort: '[[email:notif.test.short]]',
bodyLong: '[[email:notif.test.long]]',
nid: 'uid:' + socket.uid + ':test',
path: '/',
from: socket.uid,
}, next);
},
function (notifObj, next) {
emailer.send('notification', socket.uid, {
path: notifObj.path,
subject: utils.stripHTMLTags(notifObj.subject || '[[notifications:new_notification]]'),
intro: utils.stripHTMLTags(notifObj.bodyShort),
body: notifObj.bodyLong || '',
notification: notifObj,
showUnsubscribe: true,
}, next);
},
], callback);
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:
emailer.send(data.template, socket.uid, payload, callback);
await emailer.send(data.template, socket.uid, payload);
break;
}
};