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: [email protected]
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?
The exact answer to your question (handling the
[email protected]
address) depends on how your server is configured to receive mail. Ifexample.com
is the virtual domain the best you can do is collect the messages in the[email protected]
mailbox (assumingrecipient_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 thebounce
user, which delivers to a program that parses the bounce information and records it in a database or file. Seeman 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 torelay_domains
. Create/etc/postfix/transport_maps
with this content:Then append a line similar to this to
/etc/postfix/master.cf
: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.Actually, Instyle's answer is very difficult to implement if you want to support many different domains and it is wrong because:
a) With his example of
transport_maps
, all the emails sent to that domain are sent to that specific service without any regard to whether the emails are bounced emails or not. Since it uses a specific domain name, it should indeed only be bounced emails... but it cannot be guaranteed that way.b) The data sent to your script is the email itself and not the bounce message. In other words, your code may have no idea why the email was bounced (i.e. local bounce will send you the original email only.)
The correct way to do that setup in postfix is to use the bounce notification class.
1) In /etc/postfix/main.cf
2) In /etc/postfix/transport_maps
As you can see, we now tell postfix to use
[email protected]
whenever an email gets bounced. Then in the transport map, to usebulkbounce
as the service to handle any email address to[email protected]
.Finally you can define
bulkbounce
with your script:3) In /etc/postfix/master.cf
This script requires you to have a user.
nobody
is a good choice too. If you want to have a specific user, you can create it with:Without the script in
master.cf
, the emails are sent to the bulkbounce account. So if you have a script that parses emails from files, this would work without thetransport_maps
andmaster.cf
changes.From a comment below:
Most modern mailing list software already knows how to handle VERP messages if the MTA is properly configured to pass them back to the mailing list software. In the case of GNU Mailman you should checkout the FAQ page aptly named "How do I use VERP with a - delimiter (Postfix recipient_delimiter)?".
If you're making your own custom newsletter software to handle this you should ask yourself why you're re-inventing the wheel instead of using existing applications that can handle the task simply and easily for you already.