Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a python script to deliver local mail using various means. The problem is this:

  • This script has to accept multiple virtual domains defined in /etc/postfix/virtual
  • The script does the checking if the recipient is valid and the contents are as expected and exits with the appropriate code (4.x.x 5.x.x) if not

The problem is that I want the bounce to come from the recipient address (orig_to) or bounce@recipientdomain, is this possible?



@domain1     pymail
@domain2     pymail
@domain3     pymail
@domain4     pymail
@domain5     pymail

/etc/postfix/master: (contains)

pymail    unix  -       n       n       -       -       pipe
  flags=FR user=pymail argv=/path/to/ ${sender} ${recipient}


* pymail:


pymail_destination_recipient_limit = 1
transport_maps = hash:/etc/postfix/transport
virtual_alias_domains = domain1 domain2 domain3 domain4 domain5
virtual_alias_maps = hash:/etc/postfix/virtual
share|improve this question

The problem is that when postfix delivers your mail to python, it has already been accepted.

DO NOT accept mail you don't intend to deliver; backscatter bounce is one of the worst kinds of spam.

Instead, define valid recipients in postfix, instead of python, and let postfix reject unwanted or undeliverable mail.

You will also need to play with the arguments to pipe(8) and the various destination concurrency options, to get this working smoothly.

share|improve this answer
Thanks, but this script is for email to SMS, so the email has to be validated by python, not by postfix (users need to be verified, credits, destination number etc etc). And I read that postfix uses the script's exit status code (if you exit with non 0 status and a string like 4.x.x or 5.x.x) to generate the delivery/bounce status. – zeyus Jul 30 '12 at 23:24
up vote 0 down vote accepted

I couldn't find a way to do this, so in the end I just wrote in to the python script to send an error mail to the sender from the correct address.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.