Collect Bounces in Postfix – How to Guide

emailemail-serverpostfix

This is related to this question:

linux – Ways to get a bounceback report for my newsletter application? – Server Fault

Let's say I'm generating email addresses like this when I send out newsletters to identify bounces and unsubscribe them from my newsletter: bounce-123456789@example.com

I assume I'd use this in the return-path, right?

Then how would I set it up in postfix to collect all these addresses prefixed with "bounce-" into one mailbox?

Finally, I've heard people mention a soft bounce vs. a hard bounce. Can someone explain the different and how they should be counted to know when to permanently remove someone from an email newsletter?

Best Answer

The exact answer to your question (handling the bounce-xxx@example.com address) depends on how your server is configured to receive mail. If example.com is the virtual domain the best you can do is collect the messages in the bounce@example.com mailbox (assuming recipient_delimiter = -).

If example.com is the locally delivered domain for the server (mail is delivered to actual system accounts) then you can add a .forward file to the home directory of the bounce user, which delivers to a program that parses the bounce information and records it in a database or file. See man local for more info on the .forward format and how to deliver to a program.

What we do, since we send messages for a large number of domains, is use bounces.example.com as our VERP domain. This domain needs to be added to relay_domains. Create /etc/postfix/transport_maps with this content:

bounces.example.com             bulkbounce:

Then append a line similar to this to /etc/postfix/master.cf:

bulkbounce   unix  -       n       n       -       -       pipe
  user=nobody argv=/usr/local/bin/bounce_handler.py ${recipient}

The bounce_handler.py script accepts the VERP address as its command line option, parses it and makes the necessary database updates to record the bounce.

Related Topic