Detecting bounced messages by Return-Path header

狂风中的少年 提交于 2019-11-28 16:22:26

问题


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 bounce-XXXXX@yourdomain.com, 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 bounce@yourdomain.com 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


回答1:


The pertinent standard is called VERP, by the way.

You mean bounce+token@yourdomain.com, not just plain bounce@yourdomain.com. The token is what makes it unique!

Postfix will already accept mail for a+something@example.net given a valid address a@example.net 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 bounce@yourdomain.com 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 bounce@yourdomain.com to the new transport you created in master.cf:

    bounce@yourdomain.com    bounce:
    
  5. Rebuild the transport map:

    postmap /etc/postfix/transport
    


来源:https://stackoverflow.com/questions/9104404/detecting-bounced-messages-by-return-path-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!