Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting bounced messages by Return-Path header

some time ago I saw a question about detecting bounced messages:

I am working on a tool that will be sending bulk messages (not spam :) and I need to add a feature that will detect bounced messages. Is there a standard response associated with bounces? Would it be in the header of the body? By Santa, 2011-09-12


You can not rely on either the headers or the body of the bounced message to be able to reliably identify the original recipient, especially if you want to automate the process. Even if you add your own custom headers, it's likely that the bouncing server will strip them when it sends notification back to you .............................

The only piece of information that will remain completely untouched in a bounce is the return path email address -- the address that your server advertises it wants bounces sent to. Thus, the only way to automate truly accurate bounce catching is to encode the recipient directly into the return path address itself. This would typically be done by overriding your server's default return path address for each outgoing message, using a unique value per recipient, like [email protected], where XXXXX is some encoded and/or obfuscated representation of the recipient's email address or some other internal identifier. This technique requires the use of an email server which can support this type of wild card catch-all address so that you don't have to set up a new bounce account for each email address you're sending to. Assuming that, you simply configure the server to dump all such bounce-* emails to your script, which needs only to decode the XXXXX in order to determine who the original recipient was. answered Sep 12 '11 Alex Howansky

The above seems an excellent solution. Now my question is:

How to configure a Postfix (or any other) mail server to dump each and every bounced email from the [email protected] account to a script which will parse and retrieve the identity of the original recipient ? Has the script to be saved a directory in the mail server and the dumped message in the same directory ?

Will a third party email service provider allows you to configure the email account for dumping messages, and install the script in the server?

Sing

like image 375
Sing Avatar asked Feb 01 '12 22:02

Sing


1 Answers

The pertinent standard is called VERP, by the way.

You mean [email protected], not just plain [email protected]. The token is what makes it unique!

Postfix will already accept mail for [email protected] given a valid address [email protected] as long as you configure the recipient_delimiter in main.cf:

recipient_delimiter = +

There are a few different ways to configure Postfix so that it will deliver the mail to your script AND tell you what the token was. Try this:

  1. Create the address [email protected] the same way you create aliases normally in that domain: e.g. a regular alias or a virtual mailbox

  2. Create a custom delivery transport in master.cf. ${extension} means that the script will receive whatever came after the + as its first argument, and <username> should the the local uid under which the script should run.

    bounce   unix  -       n       n       -       -       pipe
      flags=R user=<username> argv=/script/which/receives/bounces ${extension}
    
  3. Create a transport map if you don't already have one:

    transport_maps = hash:/etc/postfix/transport
    
  4. Add the following line in /etc/postfix/transport to direct [email protected] to the new transport you created in master.cf:

    [email protected]    bounce:
    
  5. Rebuild the transport map:

    postmap /etc/postfix/transport
    
like image 199
Celada Avatar answered Oct 22 '22 08:10

Celada