Bounce tracking


I'm trying to set up simple bounce handling in Postfix. I was hoping not to need/want VERP, but simply trying to get Postfix to call a script with the failed (bounced/delayed) RCPT TO address, instead of sending a bounce e-mail with that bounced address in the body. (Current version is 3.1.0-3ubuntu0.3, from Ubuntu 16.04).

So far, I've tried:

notify_classes = bounce
bounce_notice_recipient = <a href="mailto: ... at example dot com"> ... at example dot com</a>
transport_maps = hash:/etc/postfix/transport_maps

bouncehandler unix - n n - - pipe
flags=FRq user=bouncehandler argv=/usr/local/bin/ --sender ${sender} --recipient ${recipient}


<a href="mailto: ... at example dot com"> ... at example dot com</a> bouncehandler:


datestamp=$(date +%Y%m%d-%H:%M)
echo "[$datestamp] $@" >> "$debug_file"

But, the only output I seem to get, is from the double bounce, and not the bounced address:

[20181130-17:43] --sender <a href="mailto:double- ... at mailserver dot">double- ... at mailserver dot</a> --recipient <a href="mailto: ... at example dot com"> ... at example dot com</a>

Postfix knows exactly which address failed, because it includes it in the mail body of bounce notices:

< ... at example dot com>: host ASPMX.L.GOOGLE.COM[2a00:1450:4013:c00::1b] said: 550-5.1.1
The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1
<a href="" title=""></a> a12si2525633edk.106 - gsmtp
(in reply to RCPT TO command)

So instead of sending that e-mail, can I call the script with that address?

Or, am I going to have to parse that message (that comes in on std-in)?




Re: Bounce tracking

By Wietse Venema at 12/03/2018 - 17:30

Wiebe Cazemier:
The pipe daemon has no access to message content fields, only the
message envelope. Putting the failed recipient address in the sender
or recipient envelope address of a bounce notification would not
be safe.

The format of Postfix bounces is documented in Internet RFCs:

RFC 3462 (Delivery Status Notifications)
RFC 3464 (Delivery Status Notifications)

Extracting the failed recipient should be a no-brainer. It's
all MIME boundaries and "label: value" stuff, with folding whitespace.