- 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:
Tomas Bures 2019-06-25 07:18:06 +02:00
parent ff66a6c39e
commit 30b361290b
42 changed files with 1366 additions and 786 deletions

View file

@ -753,11 +753,11 @@ async function migrateSettings(knex) {
if (settings.dkimApiKey) {
mailer_type = MailerType.ZONE_MTA;
mailer_settings.dkimApiKey = settings.dkimApiKey;
mailer_settings.dkimApiKey = settings.dkimApiKey || '';
mailer_settings.zoneMtaType = ZoneMTAType.WITH_HTTP_CONF;
mailer_settings.dkimDomain = settings.dkimDomain;
mailer_settings.dkimSelector = settings.dkimSelector;
mailer_settings.dkimPrivateKey = settings.dkimPrivateKey;
mailer_settings.dkimDomain = settings.dkimDomain || '';
mailer_settings.dkimSelector = settings.dkimSelector || '';
mailer_settings.dkimPrivateKey = settings.dkimPrivateKey || '';
}
}
@ -777,7 +777,7 @@ async function migrateSettings(knex) {
verp_hostname: settings.verpUse ? settings.verpHostname : null,
mailer_type,
mailer_settings: JSON.stringify(mailer_settings),
x_mailer: settings.x_mailer,
x_mailer: settings.x_mailer || '',
namespace: getGlobalNamespaceId()
});
@ -810,7 +810,7 @@ async function addFiles(knex) {
table.string('mimetype');
table.integer('size');
table.timestamp('created').defaultTo(knex.fn.now());
table.index(['entity', 'originalname'])
table.index(['entity', 'originalname']);
});
}
}

View file

@ -0,0 +1,63 @@
const entityTypesWithFiles = {
campaign: {
file: 'files_campaign_file',
attachment: 'files_campaign_attachment',
},
template: {
file: 'files_template_file'
},
mosaico_template: {
file: 'files_mosaico_template_file',
block: 'files_mosaico_template_block'
}
};
exports.up = (knex, Promise) => (async() => {
await knex.schema.table('queued', table => {
table.integer('send_configuration').unsigned().notNullable();
table.integer('type').unsigned().notNullable(); // The values come from campaign-sender.js:MessageType
table.text('data', 'longtext');
});
const queued = await knex('queued')
.leftJoin('campaigns', 'queued.campaign', 'campaigns.id')
.select(['queued.id', 'queued.trigger', 'queued.campaign', 'campaigns.send_configuration']);
for (const queuedEntry of queued) {
const data = {};
if (queued.trigger) {
data.triggerId = queuedEntry.trigger;
data.campaignId = queuedEntry.campaign;
}
knex('queued')
.where('id', queuedEntry.id)
.update({
send_configuration: queuedEntry.send_configuration,
data: JSON.stringify(data)
});
}
await knex.schema.table('queued', table => {
table.dropColumn('trigger');
table.dropColumn('campaign');
});
for (const type in entityTypesWithFiles) {
const typeEntry = entityTypesWithFiles[type];
for (const subType in typeEntry) {
const subTypeEntry = typeEntry[subType];
await knex.schema.table(subTypeEntry, table => {
table.boolean('delete_pending').notNullable().defaultTo(false);
table.integer('lock_count').notNullable().defaultTo(0);
});
}
}
})();
exports.down = (knex, Promise) => (async() => {
})();

View file

@ -0,0 +1,15 @@
exports.up = (knex, Promise) => (async() => {
await knex.schema.table('send_configurations', table => {
table.dropColumn('subject');
table.dropColumn('subject_overridable');
});
await knex.schema.table('campaigns', table => {
table.renameColumn('subject_override', 'subject');
});
await knex('campaigns').whereNull('subject').update('subject', '');
})();
exports.down = (knex, Promise) => (async() => {
})();