Greylisting with Exim and PostgreSQL
Greylisting is a technique to reduce spam by temporarily rejecting emails from unknown senders. The mail server is then expected to retry sending the email after a short delay. Since most spam is sent by machines that don't retry, this is an effective way to filter out a large portion of spam.
I've implemented greylisting for my mail server using Exim and PostgreSQL. Here's how it works:
How it works
When an email arrives, Exim checks if the combination of sender, recipient, and sending server has been seen before. If not, the email is temporarily rejected with a "try again later" response. If the combination has been seen before and enough time has passed, the email is accepted and the database is updated.
Implementation
The implementation uses a PostgreSQL database to store the greylisting information. A simple table stores the sender, recipient, sending server, and timestamp of the last attempt.
Configuration
To enable greylisting in Exim, you need to add an ACL rule that queries the database and decides whether to accept or reject the email. The rule should be placed in the DATA ACL.
Results
Since I've enabled greylisting on my mail server, the amount of spam has decreased significantly. Most spam never retries, so it's never delivered. Legitimate emails are still delivered, just with a slight delay on the first message from a new sender.