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

To drop message and not processing next hooks #329

Closed vivekpatel5996 closed 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 ?

Thanks.

roshanjonah commented 1 year ago

Any idea how to achieve this? @louis-lau

andris9 commented 1 year ago

You need to reject the email. Otherwise, the specific plugin is logged as failed.

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

See this example: https://github.com/zone-eu/zone-mta/blob/master/plugins/core/rspamd/index.js#L102

vivekpatel5996 commented 1 year ago

Hi @andris9.

Thanks for the reply. But it seems it works only with message:queue hooks and not the sender:connection.

Thanks,

roshanjonah commented 1 year ago

@andris9, your help would be much appreciated. Thank you