- Refactoring of the mail sending part. Mail queue (table 'queued') is now used also for all test emails.
- More options how to send test emails. - Fixed problems with pausing a campaign (#593) - Started rework of transactional sender of templates (#606), however this contains functionality regression at the moment because it does not interpret templates as HBS. It needs HBS option for templates as described in https://github.com/Mailtrain-org/mailtrain/issues/611#issuecomment-502345227 TODO: - detect sending errors connected to not able to contact the mailer and pause/retry campaing and queued sending - don't mark the recipients as BOUNCED - add FAILED campaign state and fall into it if sending to campaign consistently fails (i.e. the error with sending is not temporary) - if the same happends for queued email, delete the message
This commit is contained in:
parent
ff66a6c39e
commit
30b361290b
42 changed files with 1366 additions and 786 deletions
|
@ -16,8 +16,10 @@ const contextHelpers = require('../lib/context-helpers');
|
|||
const shares = require('../models/shares');
|
||||
const slugify = require('slugify');
|
||||
const passport = require('../lib/passport');
|
||||
const TemplateSender = require('../lib/template-sender');
|
||||
const templates = require('../models/templates');
|
||||
const campaigns = require('../models/campaigns');
|
||||
const {castToInteger} = require('../lib/helpers');
|
||||
const {getSystemSendConfigurationId} = require('../../shared/send-configurations');
|
||||
|
||||
class APIError extends Error {
|
||||
constructor(msg, status) {
|
||||
|
@ -236,7 +238,7 @@ router.postAsync('/blacklist/add', passport.loggedIn, async (req, res) => {
|
|||
input[(key || '').toString().trim().toUpperCase()] = (req.body[key] || '').toString().trim();
|
||||
});
|
||||
if (!(input.EMAIL) || (input.EMAIL === '')) {
|
||||
throw new Error('EMAIL argument is required');
|
||||
throw new APIError('EMAIL argument is required', 400);
|
||||
}
|
||||
|
||||
await blacklist.add(req.context, input.EMAIL);
|
||||
|
@ -253,7 +255,7 @@ router.postAsync('/blacklist/delete', passport.loggedIn, async (req, res) => {
|
|||
input[(key || '').toString().trim().toUpperCase()] = (req.body[key] || '').toString().trim();
|
||||
});
|
||||
if (!(input.EMAIL) || (input.EMAIL === '')) {
|
||||
throw new Error('EMAIL argument is required');
|
||||
throw new APIError('EMAIL argument is required', 400);
|
||||
}
|
||||
|
||||
await blacklist.remove(req.oontext, input.EMAIL);
|
||||
|
@ -288,32 +290,30 @@ router.getAsync('/rss/fetch/:campaignCid', passport.loggedIn, async (req, res) =
|
|||
|
||||
router.postAsync('/templates/:templateId/send', async (req, res) => {
|
||||
const input = {};
|
||||
Object.keys(req.body).forEach(key => {
|
||||
input[
|
||||
(key || '')
|
||||
.toString()
|
||||
.trim()
|
||||
.toUpperCase()
|
||||
] = req.body[key] || '';
|
||||
});
|
||||
|
||||
try {
|
||||
const templateSender = new TemplateSender({
|
||||
context: req.context,
|
||||
locale: req.locale,
|
||||
templateId: req.params.templateId
|
||||
});
|
||||
const info = await templateSender.send({
|
||||
data: input.DATA,
|
||||
email: input.EMAIL,
|
||||
sendConfigurationId: input.SEND_CONFIGURATION_ID,
|
||||
subject: input.SUBJECT,
|
||||
variables: input.VARIABLES
|
||||
});
|
||||
res.status(200).json({ data: info });
|
||||
} catch (e) {
|
||||
throw new APIError(e.message, 400);
|
||||
for (const key in req.body) {
|
||||
const sanitizedKey = key.toString().trim().toUpperCase();
|
||||
input[sanitizedKey] = req.body[key] || '';
|
||||
}
|
||||
|
||||
const templateId = castToInteger(req.params.templateId, 'Invalid template ID');
|
||||
|
||||
let sendConfigurationId;
|
||||
if (!('SEND_CONFIGURATION_ID' in input)) {
|
||||
sendConfigurationId = getSystemSendConfigurationId();
|
||||
} else {
|
||||
sendConfigurationId = castToInteger(input.SEND_CONFIGURATION_ID, 'Invalid send configuration ID');
|
||||
}
|
||||
|
||||
if (!input.EMAIL || input.EMAIL === 0) {
|
||||
throw new APIError('Missing email(s)', 400);
|
||||
}
|
||||
|
||||
const emails = input.EMAIL.split(',');
|
||||
|
||||
const info = await templates.sendAsTransactionalEmail(req.context, templateId, sendConfigurationId, emails, input.SUBJECT, input.VARIABLES);
|
||||
|
||||
res.json({ data: info });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
const router = require('../lib/router-async').create();
|
||||
const CampaignSender = require('../lib/campaign-sender');
|
||||
const {CampaignSender} = require('../lib/campaign-sender');
|
||||
|
||||
|
||||
router.get('/:campaign/:list/:subscription', (req, res, next) => {
|
||||
const cs = new CampaignSender();
|
||||
cs.init({campaignCid: req.params.campaign})
|
||||
cs.initByCampaignCid(req.params.campaign)
|
||||
.then(() => cs.getMessage(req.params.list, req.params.subscription))
|
||||
.then(result => {
|
||||
const {html} = result;
|
||||
|
|
|
@ -114,6 +114,12 @@ router.postAsync('/campaigns-link-clicks-table/:campaignId', passport.loggedIn,
|
|||
return res.json(await campaigns.listLinkClicksDTAjax(req.context, castToInteger(req.params.campaignId), req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/campaign-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||
const data = req.body;
|
||||
const result = await campaigns.testSend(req.context, data);
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
|
@ -5,7 +5,6 @@ const templates = require('../../models/templates');
|
|||
|
||||
const router = require('../../lib/router-async').create();
|
||||
const {castToInteger} = require('../../lib/helpers');
|
||||
const CampaignSender = require('../../lib/campaign-sender');
|
||||
|
||||
|
||||
router.getAsync('/templates/:templateId', passport.loggedIn, async (req, res) => {
|
||||
|
@ -39,10 +38,4 @@ router.postAsync('/templates-by-namespace-table/:namespaceId', passport.loggedIn
|
|||
return res.json(await templates.listByNamespaceDTAjax(req.context, castToInteger(req.params.namespaceId), req.body));
|
||||
});
|
||||
|
||||
router.postAsync('/template-test-send', passport.loggedIn, passport.csrfProtection, async (req, res) => {
|
||||
const data = req.body;
|
||||
const result = await CampaignSender.testSend(req.context, data.listCid, data.subscriptionCid, data.campaignId, data.sendConfigurationId, data.html, data.text);
|
||||
return res.json(result);
|
||||
});
|
||||
|
||||
module.exports = router;
|
Loading…
Add table
Add a link
Reference in a new issue