haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

Reporting the real {reason} in LMTP-related bounced messages #477

Closed abhas closed 10 years ago

abhas commented 10 years ago

When delivering a message via LMTP fails because the recipient ID does not exist, dovecot responds with a verbose error which is correctly recorded in the Haraka logs:

[outbound] recipient <adfd@abhas.in> rejected: 550 5.1.1 <adfd@abhas.in> User doesn't exist: adfd@abhas.in

So accordingly, I'd expect {reason} to contain: 550 5.1.1 <adfd@abhas.in> User doesn't exist: adfd@abhas.in. However, the resulting bounce that outbound.js sends only contains: Some recipients failed: <adfd@abhas.in>. Is there a way to also append the error response from the LMTP server server here?

I'd be glad to do this myself and send across a pull request if you can point out where this change would need to be done.

The reason the verbose error might be important is that Dovecot might reject the recipient because its disabled or its overrun its quota or other such reasons. And so it might be useful to communicate these exactly.

smfreegard commented 10 years ago

Can you try this and let me know if it works:

diff --git a/outbound.js b/outbound.js
index e065fab..4f43dda 100644
--- a/outbound.js
+++ b/outbound.js
@@ -1173,6 +1173,10 @@ function populate_bounce_message (from, to, reason, hmail, cb) {
         from: from,
         to:   to,
         reason: reason,
+        extended_reason: hmail.todo.rcpt_to.map(function (recip) {
+            if (recip.reason)
+                return recip.original + ': ' + recip.reason
+        }).join('\n'),
         pid: process.pid,
         msgid: '<' + utils.uuid() + '@' + config.get('me') + '>',
     };

You'll then need to add {extended_reason} into your bounce template.

abhas commented 10 years ago

Thanks a lot! This worked quite well. Would this become a core feature sometime?

baudehlo commented 10 years ago

Yes. It will go into the next release. But the overall plan is to make the bounce messages RFC 3464 compliant.

On Tue, Feb 25, 2014 at 11:35 AM, Abhas Abhinav notifications@github.comwrote:

Thanks a lot! This worked quite well. Would this become a core feature sometime?

— Reply to this email directly or view it on GitHubhttps://github.com/baudehlo/Haraka/issues/477#issuecomment-36027115 .