Script to generate a list of valid email recipients from a qmail setup

Last week I set-up a Postfix+MailScanner+ClamAV anti-spam and anti-virus mail relay server. Testing seemed all good, except that it was scanning lots of bogus email addresses, e.g. to

Postfix provides a relay_recipients file (at least thats what the MailScanner setup called it) where you specify the specific email addresses that you are prepared to accept email for.

In the old days we used SMTP VRFY – which people dropped because it was a way to verify good email addresses and clean spam lists.   However, by dropping it it seems the spammers just ignored cleaning and just blast out to any and all email address they could find.  The irony being that the problems are now worse because we are constantly being bombarded by spam to bogus addresses.

As my primary email system is (still) qmail I needed a way to build a list of valid emails that qmail would accept – so I set about writing a perl script that would process the control/virtualdomains users/assign and dot-qmail files in the same way that qmail would.

The result is here:

Feel free to make use of the script – hopefully it can help others too.   Note that it doesn’t handle ~alias users, nor if you have a database backed system – but manual and vpopmail setups should be just fine.  No warranty implied or given though :) Use at your own risk.

Once I added the relay_recipients file to the postfix relay and waited a few days, awstats reported that 99.8% of all my email was to bogus addresses – wow!  That is a massive saving on CPU (antispam/av scanning) and traffic.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.