Built-in Zone MTA
Plugin for ZoneMTA for per-message DKIM keys.
This commit is contained in:
parent
d103a2cc79
commit
77c64f487d
18 changed files with 231 additions and 110 deletions
45
server/lib/builtin-zone-mta.js
Normal file
45
server/lib/builtin-zone-mta.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const fork = require('child_process').fork;
|
||||
const log = require('./log');
|
||||
const path = require('path');
|
||||
|
||||
let zoneMtaProcess;
|
||||
|
||||
module.exports = {
|
||||
spawn
|
||||
};
|
||||
|
||||
function spawn(callback) {
|
||||
if (config.builtinZoneMTA.enabled) {
|
||||
log.info('ZoneMTA', 'Starting built-in Zone MTA process');
|
||||
|
||||
zoneMtaProcess = fork(
|
||||
path.join(__dirname, '..', '..', 'zone-mta', 'index.js'),
|
||||
['--config=' + path.join(__dirname, '..', '..', 'zone-mta', 'config', 'zonemta.js')],
|
||||
{
|
||||
cwd: path.join(__dirname, '..', '..', 'zone-mta'),
|
||||
env: {NODE_ENV: process.env.NODE_ENV}
|
||||
}
|
||||
);
|
||||
|
||||
zoneMtaProcess.on('message', msg => {
|
||||
if (msg) {
|
||||
if (msg.type === 'zone-mta-started') {
|
||||
log.info('ZoneMTA', 'ZoneMTA process started');
|
||||
return callback();
|
||||
} else if (msg.type === 'entries-added') {
|
||||
senders.scheduleCheck();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
zoneMtaProcess.on('close', (code, signal) => {
|
||||
log.error('ZoneMTA', 'ZoneMTA process exited with code %s signal %s', code, signal);
|
||||
});
|
||||
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
|
@ -328,9 +328,9 @@ class CampaignSender {
|
|||
|
||||
const getOverridable = key => {
|
||||
if (sendConfiguration[key + '_overridable'] && this.campaign[key + '_override'] !== null) {
|
||||
return campaign[key + '_override'];
|
||||
return campaign[key + '_override'] || '';
|
||||
} else {
|
||||
return sendConfiguration[key];
|
||||
return sendConfiguration[key] || '';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ const transports = new Map();
|
|||
async function getOrCreateMailer(sendConfigurationId) {
|
||||
let sendConfiguration;
|
||||
|
||||
if (!sendConfiguration) {
|
||||
if (!sendConfigurationId) {
|
||||
sendConfiguration = await sendConfigurations.getSystemSendConfiguration();
|
||||
} else {
|
||||
sendConfiguration = await sendConfigurations.getById(contextHelpers.getAdminContext(), sendConfigurationId, false, true);
|
||||
|
@ -38,8 +38,35 @@ function invalidateMailer(sendConfigurationId) {
|
|||
|
||||
|
||||
|
||||
function _addDkimKeys(transport, mail) {
|
||||
const sendConfiguration = transport.mailer.sendConfiguration;
|
||||
|
||||
if (sendConfiguration.mailer_type === sendConfigurations.MailerType.ZONE_MTA) {
|
||||
if (!mail.headers) {
|
||||
mail.headers = {};
|
||||
}
|
||||
|
||||
const dkimDomain = sendConfiguration.mailer_settings.dkimDomain;
|
||||
const dkimSelector = (sendConfiguration.mailer_settings.dkimSelector || '').trim();
|
||||
const dkimPrivateKey = (sendConfiguration.mailer_settings.dkimPrivateKey || '').trim();
|
||||
|
||||
if (dkimSelector && dkimPrivateKey) {
|
||||
const from = (mail.from.address || '').trim();
|
||||
const domain = from.split('@').pop().toLowerCase().trim();
|
||||
|
||||
mail.headers['x-mailtrain-dkim'] = JSON.stringify({
|
||||
domainName: dkimDomain || domain,
|
||||
keySelector: dkimSelector,
|
||||
privateKey: dkimPrivateKey
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function _sendMail(transport, mail, template) {
|
||||
_addDkimKeys(transport, mail);
|
||||
|
||||
let tryCount = 0;
|
||||
const trySend = (callback) => {
|
||||
tryCount++;
|
||||
|
@ -209,6 +236,7 @@ async function _createTransport(sendConfiguration) {
|
|||
}
|
||||
|
||||
transport.mailer = {
|
||||
sendConfiguration,
|
||||
throttleWait: bluebird.promisify(throttleWait),
|
||||
sendTransactionalMail: async (mail, template) => await _sendTransactionalMail(transport, mail, template),
|
||||
sendMassMail: async (mail, template) => await _sendMail(transport, mail)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue