zone-eu / zone-mta

📤 Modern outbound MTA cross platform and extendable server application
European Union Public License 1.2
599 stars 96 forks source link

sendingZone question #286

Closed matteomattei closed 2 years ago

matteomattei commented 2 years ago

Hello, I tried to configure a programmatic different message delivery based on sendingZone. This is an extract of my configuration:

"plugins": {
    "000-headers": {
      "enabled": ["receiver"],
      "interfaces": ["feeder", "feedertls", "feederssl"]
    },
    "core/example-plugin": false,
    "core/default-headers": {
      "enabled": ["receiver", "main", "sender"],
      "allowRoutingHeaders": ["api", "bounce", "feederssl"],
      "addMissing": ["message-id", "date"],
      "futureDate": false,
      "xOriginatingIP": true
    }
}
[...]
"zones": {
    "zone2": {
      "preferIPv6": false,
      "ignoreIPv6": true,
      "processes": 1,
      "connections": 5,
      "pool": "pool2",
      "routingHeaders": { "x-zone-id": "2" }
    }
  }
[...]
"smtpInterfaces": {
    "feederssl": {
      "enabled": true,
      "processes": 1,
      "maxSize": 20971520,
      "host": "0.0.0.0",
      "port": 2465,
      "authentication": true,
      "authOptional": true,
      "maxRecipients": 1000,
      "starttls": true,
      "secure": true,
      "key": "./certs/san-emailvlt.net.key",
      "cert": "./certs/san-emailvlt.net.pem"
    },
 }
[...]

This is the content of 000-headers.js plugin:

'use strict';
module.exports.title = 'Add custom headers';

module.exports.init = (app, done) => {
    app.addHook('message:headers', (envelope, messageinfo, next) => {
        console.log('adding x-sending-zone');
        envelope.headers.add('x-sending-zone','zone2');
        return next();
    });
    done();
};

I would expect every message should have "zone2" added in 'x-sending-zone' header but it seems that the core/default-headers plugin is triggered BEFORE the 000-headers plugin, in fact the x-sending-zone header field is not present at that point and the zone used is always the default.

Can you clarify how the sendingZone works?

Thanks

matteomattei commented 2 years ago

It is possible with the queue:route hook:

app.addHook('queue:route', async (envelope, routing, next) => {
    routing.deliveryZone = 'zone2';
    next();
});