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

Stop processing next hooks #330

Open vivekpatel5996 opened 1 year ago

vivekpatel5996 commented 1 year ago

Hello,

I am throwing an error from the sender:connection hook, even though next hooks are called and mail is delivered.

I have some condition that checks if DKIM is not available then throw the error and not proceed further hooks and drop the message but still it's processing and printing console from sender:delivered hook.

app.addHook('sender:connection', async (delivery, options, next) => { throw new Error("No DKIM available") }

app.addHook('sender:delivered', async (delivery, info, next) => { console.log("Delivered") }

Anyone can help on how to throw the error and not processing further hooks ?

And is there any proper way to drop the message from the queue and not process that particular message ?

created issue https://github.com/zone-eu/zone-mta/issues/329#issue-1690509576 but not resolved by the solution.

Thanks.

louis-lau commented 1 year ago

This is a free open source project. A tag and reminder after only 8 hours of the issue being opened isn't helpful, things like this can lead to stress for open source maintainers. I know this is probably not your intention at all! But I thought I would just mention it. :)

Andris and others are already watching this repository and will receive notifications without an extra mention.

roshanjonah commented 1 year ago

Sorry about that. My apologies. That was not my intention. Won't happen again :)

roshanjonah commented 1 year ago

@andris9 It would be great if you could please look into this.

dazoot commented 1 year ago

I think @andris9 made it very clear that you need to throw an app.reject exception.

throw app.reject(envelope, 'reject', messageInfo, 'No DKIM available')

By just throwing a random Error, the plugin will be marked as failed but other plugins / hooks will continue to run. Also make sure that the 2 hooks you have pasted are from the same plugin, otherwise, the one with console.log will keep running.

I see no issue here. Should have this closed.

rjnz2023 commented 3 months ago

@dazoot @andris9 This seems to work only with message:queue hooks and not the sender:connection which is what we are using. So how do we handle that? Any ideas?