Greylisting is a technique that will reject the first delivery attempt of an email, and whitelist the sender and its recipient emails combination if the sender tried to send the same email again. It's an effective method to get rid of spam because most spam emails are only sent once and if it fails to be delivered the spammers usually don't care, as it's all about volume.
A normally configured SMTP server will try again after being refused once, and if it does then the domain will be whitelisted automatically and future emails will not be delayed.
Installation and configuration
It's super simple to install and configure in combination with Postfix.
- Install postgrey, the Postfix policy server implementing greylisting:
apt install postgrey
/etc/postfix/main.cfto add the following line at the end of
... permit_mynetworks, reject_unauth_destination, check_policy_service inet:127.0.0.1:10023
- Restart Postfix (postgrey should already be running after installation)
service postfix restart
- As usual
/var/log/mail.infois your friend, postgrey will log things there
- A typical successful postgrey check will go like this:
- First attempt rejected:
XXX XX XX:XX:XX xxx postgrey: action=greylist, reason=new, client_name=xxx.xxx.xxx, client_address=999.999.999.999, email@example.com, firstname.lastname@example.org XXX XX XX:XX:XX xxx postfix/smtpd: NOQUEUE: reject: RCPT from xxx.xxx.xxx[999.999.999.999]: 450 4.2.0 <email@example.com>: Recipient address rejected: Greylisted, see http://postgrey.schweikert.ch/help/yyy.yyy.yyy.html; from=<firstname.lastname@example.org> to=<email@example.com> proto=ESMTP helo=<xxx.xxx.xxx>
- Second attempt successful:
XXX XX XX:XX:XX xxx postgrey: action=pass, reason=triplet found, delay=500, client_name=xxx.xxx.xxx, client_address=999.999.999.999, firstname.lastname@example.org, email@example.com