0

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?


Setup:

/etc/postfix/virtual:

@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/script.py ${sender} ${recipient}

/etc/postfix/transport:

* pymail:

/etc/postfix/main.cf:

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
zeyus
  • 33
  • 1
  • 7

2 Answers2

0

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.

adaptr
  • 16,576
  • 23
  • 34
  • 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
0

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.

zeyus
  • 33
  • 1
  • 7