Today I decided to install Postgrey on my mail server to help reduce the mass influx of crap I get in my mailbox on a daily basis. I’m not the type of person to have only one email address, I feel the need to use a catch all as I despise the thought of losing emails. And yes there are several thousand items in my inbox I haven’t brought myself to removing.
Anyway I’ve had it running a couple of hours now and it looks to be pretty efficient in its job and its FAR easier to setup than spamassassin etc.
What is it ?
In a nutshell, Postgrey rejects incoming emails. Yes that sounds drastic but a legitimate mail server will resend the message where as the mailservers spammers use tend to send out messages in such bulk they want to get the job over and done with as quickly as possible and don’t care if they miss a few recipients. Thats the idea anyway.
On with the setup ..
Firstly I am using postfix on a ubuntu 6.06 based server & assume all instructions are executed as sudo.
1. Install with apt-get
apt-get install postgrey
2. Edit the postfix configuration so it will work with postgrey. I use nano as an editor.
nano /etc/postfix/main.cf
Find the line – smtpd_recipient_restrictions =
Add the following lines, you may already have the first, I did.
reject_unauth_destination
check_policy_service inet:127.0.0.1:60000
3. Alter postfix settings (Optional)
By default, postfix will delay an incoming message for 300s, I think 5 minutes is a bit steep so you can change this, although this may increase the chances of receiving spam. I changed mine to 1 minute.
nano /etc/default/postgrey
Find the line POSTGREY_OPTS=”–inet=127.0.0.1:60000 –delay=300″ and change 300 to 60 so you end up with POSTGREY_OPTS=”–inet=127.0.0.1:60000 –delay=60″
Next you may wish to specify certain email addresses or domains that you wish postgrey to ignore as you trust them. These configurations are in the whitelist file.
nano /etc/postgrey/whitelist_clients
If you trust every address from hotmail (EXAMPLE ONLY !) you can add @hotmail.com on its own line in this file.
4. Restart Everything
/etc/init.d/postgrey restart
postfix reload
Thats it. You can monitor your mail log using tail /var/log/mail.log -f whilst sending an email to yourself from hotmail for example, and you should see the mail being rejected to make sure its working.
FAO UBUNTU 7.10 (GUTSY GIBBON) Users.
After upgrading my server OS from 6.06 to 7.10, I had noticed that mail wasn’t coming through and I was seeing lines like this;
Ubuntu-710 postgrey[18179]: fatal: Can't call method "txn_commit" on an undefined value at /usr/sbin/postgrey line 223.
in my mail logs. As soon as the error occurs, The Postgrey daemon would stop running, Postfix was then unable to communicate with it and no more mail would be delivered correctly, OUCH!
Anyway the good news is the problem was discovered to be an incompatiability between Postgray and one of the OS libraries – libdb . My immediate solution was to setup a cron job that checked to see if Postgray was still running, if not – it would fire it up again, Not great but effective I know.
Thankfully now an updated version of libdb is available and you can get it by adding the following apt source to sources.list;
deb http://us.archive.ubuntu.com/ubuntu gutsy-proposed main
and then updating libdb with the following apt call;
1 | admin December 12th, 2007 at 9:22 amapt-get update && apt-get install libdb4.4