zone-eu / zone-mta

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

change sendingZone after X delivery attempts #157

Closed dazoot closed 5 years ago

dazoot commented 5 years ago

Is it possible to change the sendingZone of an existing queued message ? I am investigating if we can do a sendingZone failover plugin, after X delivery attempts for example.

andris9 commented 5 years ago

Interesting question, never thought of that. I guess it should be possible as zone is defined by sendingZone property in the message queue collection in database. All you need to do to change zone would be to change this property (eg. from “default” to “someotherzone”)

dazoot commented 5 years ago

Do the plugins have access to the delivery attempts (count, smtp error messages) ? Updating the sendingZone property in the plugin code, saves it to the mongo DB ?

andris9 commented 5 years ago

Plugins should see previous delivery attempts from delivery._deferredproperty.

I pushed out zone-mta v1.12.0 where you can update queue entry keys in db using delivery.updates object (only applies to "sender:*" hooks)

app.addHook('sender:headers', (delivery, connection, next) => {
    if (!delivery.updates) {
        // make sure the updates object exists
        delivery.updates = {};
    }
    // override Zone for this message if it is deferred, no effect if message bounces or is accepted
    delivery.updates.sendingZone = 'someother';

    next();
});
Luskan777 commented 2 years ago

Plugins should see previous delivery attempts from delivery._deferredproperty.

I pushed out zone-mta v1.12.0 where you can update queue entry keys in db using delivery.updates object (only applies to "sender:*" hooks)

app.addHook('sender:headers', (delivery, connection, next) => {
    if (!delivery.updates) {
        // make sure the updates object exists
        delivery.updates = {};
    }
    // override Zone for this message if it is deferred, no effect if message bounces or is accepted
    delivery.updates.sendingZone = 'someother';

    next();
});

Hi, is this still working?

I tried, and it didn't work.

There's something to be customized?

dazoot commented 2 years ago

Yes it works fine.

We use this:

delivery._deferred.response

To see the actual bounce message.

And:

let deferredCount = (delivery._deferred && delivery._deferred.count) || 0;

To see the actual deferred count.

Luskan777 commented 2 years ago

Hi,

Thank you so much @dazoot .

But could you show more of your code that you used to solve the problem? I'm new to JavaScript, I don't know what context to use, seeing a little more would help me a lot.

Luskan777 commented 2 years ago

Hello, I won't need your code model anymore, with your help in another issue I managed to finish the development of plugin #299