mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: closes #13641, log test email sending errors server side
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const winston = require('winston');
|
||||||
|
|
||||||
const meta = require('../../meta');
|
const meta = require('../../meta');
|
||||||
const userDigest = require('../../user/digest');
|
const userDigest = require('../../user/digest');
|
||||||
const userEmail = require('../../user/email');
|
const userEmail = require('../../user/email');
|
||||||
@@ -14,55 +16,59 @@ Email.test = async function (socket, data) {
|
|||||||
...(data.payload || {}),
|
...(data.payload || {}),
|
||||||
subject: '[[email:test-email.subject]]',
|
subject: '[[email:test-email.subject]]',
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
|
switch (data.template) {
|
||||||
|
case 'digest':
|
||||||
|
await userDigest.execute({
|
||||||
|
interval: 'month',
|
||||||
|
subscribers: [socket.uid],
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
switch (data.template) {
|
case 'banned':
|
||||||
case 'digest':
|
Object.assign(payload, {
|
||||||
await userDigest.execute({
|
username: 'test-user',
|
||||||
interval: 'month',
|
until: utils.toISOString(Date.now()),
|
||||||
subscribers: [socket.uid],
|
reason: 'Test Reason',
|
||||||
});
|
});
|
||||||
break;
|
await emailer.send(data.template, socket.uid, payload);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'banned':
|
case 'verify-email':
|
||||||
Object.assign(payload, {
|
case 'welcome':
|
||||||
username: 'test-user',
|
await userEmail.sendValidationEmail(socket.uid, {
|
||||||
until: utils.toISOString(Date.now()),
|
force: 1,
|
||||||
reason: 'Test Reason',
|
template: data.template,
|
||||||
});
|
subject: data.template === 'welcome' ? `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]` : undefined,
|
||||||
await emailer.send(data.template, socket.uid, payload);
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'verify-email':
|
case 'notification': {
|
||||||
case 'welcome':
|
const notification = await notifications.create({
|
||||||
await userEmail.sendValidationEmail(socket.uid, {
|
type: 'test',
|
||||||
force: 1,
|
bodyShort: '[[email:notif.test.short]]',
|
||||||
template: data.template,
|
bodyLong: '[[email:notif.test.long]]',
|
||||||
subject: data.template === 'welcome' ? `[[email:welcome-to, ${meta.config.title || meta.config.browserTitle || 'NodeBB'}]]` : undefined,
|
nid: `uid:${socket.uid}:test`,
|
||||||
});
|
path: '/',
|
||||||
break;
|
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': {
|
default:
|
||||||
const notification = await notifications.create({
|
await emailer.send(data.template, socket.uid, payload);
|
||||||
type: 'test',
|
break;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
default:
|
winston.error(err.stack);
|
||||||
await emailer.send(data.template, socket.uid, payload);
|
throw err;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user