pythonpostfix-mtaverp

Send VERP compliant email using python and postfix


I want to be able to send emails in python so that I can parse bounces. VERP seems to be the solution to this. However I don't receive the bounce notification when I set my from address (not the MIMEMultipart object's "From" value) to include the VERP delimiter.

Can I just form my own VERP sender (i.e. to send to user@domain.com, can I just set my From: address for that recipient "mysender+user-domain-com.mydomain.com") and expect it to work, or do I need to configure postfix to correctly parse the failed DSN somehow? My problem is receipt of the failure notice, not getting the message to deliver to valid recipients when I do this.

Maybe an example will help.

When I send email from myuser@domain.com, I receive bounce notices just fine.

When I send email from myuser+verp_identifier@domain.com, I don't receive any bounce notices. (Although correctly addressed emails, e.g., to: valid_user@gmail.com go through just fine.) Perl's Mail module has a Verp sub-module, does python have anything like this?


Solution

  • You should use "Return-Path" not FROM as the address to which a bounced message is sent. Specifying the return path in an outbound message using Postfix doesn't require special configuration.

    The configuration requirement for Postfix to handle variable inbound messages can be handled with the + in an address because the + and everything that follows are usually ignored. So setting Return-Path to joe+bounce@here.com should be delivered to joe@here.com with the To address joe+bounce@here.com. Programmatic handling of the message could be done with the addition of a filter to the master.cf file.

    Put this in the service list:

    smtp      inet  n       -       -       -       -       smtpd
      -o content_filter=filter:dummy
    

    and define the filter here:

    filter    unix  -       n       n       -      10       pipe
      flags=Rq user=filter null_sender=
      argv=/home/filter/InboundProcessor.py -f ${sender} -- ${recipient}
    

    This will cause the InboundProcessor.py script to receive all inbound messages via pipe. If the To address contains a + followed some bounce key value you can associate with an address that is no longer valid, you can mark that address inactive in your database.