[Cialug] Disable postfix bounce messages?

Matthew Nuzum newz at bearfruit.org
Wed Oct 31 09:45:26 CDT 2007


On 10/31/07, Jeff Davis <jdavis at geolearning.com> wrote:
> If you use relay_recipient_maps at the relay, you just don't accept mail
> for users that don't exist thereby avoiding having to handle bounced messages
> for misaddressed mail.
>
> http://www.postfix.org/postconf.5.html#relay_recipient_maps

It just so happens I was working out a solution to this last night.

In main.cf I have:
relay_recipient_maps = hash:/etc/postfix/relay_recipients
hash:/etc/postfix/another_list hash:/etc/postfix/yet_another_list

Then I have a shell script that uses scp and works like this:

scp hosting:/etc/postfix/{local-host-names,virtusertable} .
for i in `egrep -v '^#' local-host-names`; do echo -e $i\\t  x; done >
domains_list
for i in `egrep -v '^#' virtusertable  | cut -f 1 --delimiter=" "`; do
echo -e $i\\tx; done > another_list

After all this is done I run
postmap another_list yet_another_list

This is for a secondary mx mailserver that acts as the backup for two
mail servers, one using standard text files, the other using a
postgresql database. The complimentary python script that does the
same thing as above but for the database mailserver looks like this:

#!/usr/bin/python

""" Grab updates of domains and users needed for backup mx service
    and process them into a usable format
"""

import psycopg
try:
    conn = psycopg.connect("dbname='x' user='y' host='z' password='pw'");
except:
    print "error"

domains = conn.cursor()
domains.execute("""SELECT distinct domain FROM domains WHERE
receive_mail = 't'""")
rows = domains.fetchall()

try:
    f = open('yet-another-domains-list','w')
except:
    print "error opening file"

for row in rows:
    f.write("%s\tx\n" % row[0])

f.close()
domains.close()

aliases = conn.cursor()
aliases.execute("""SELECT distinct alias FROM users_mailbox""")
rows = aliases.fetchall()

try:
    f = open('yet-another-list','w')
except:
    print "error opening file"

for row in rows:
    f.write("%s\tx\n" % row[0])

f.close()
aliases.close()

-- 
Matthew Nuzum
newz2000 on freenode


More information about the Cialug mailing list