Greylisting Postfix


Greylisting has proven to be a pretty effective method for reducing the amount of spam you receive.  It works by temporarily rejecting emails.  Valid email servers will then retry delivery, and be allowed through while spammers will (hopefully) give up.  See for more info.

The postgrey application at provides a simple way to implement greylisting for postfix mail servers.

Greylisting would have saved Peter in Samoa

Recently Peter here at RimuHosting went to Samoa for a week (nice for some).  He found himself on a 9600 baud internet connection.  And there was no way it was keeping up with the 200-odd spam emails that arrived in his inbox each day.  After implementing greylisting the spam has dropped down to less than a dozen or so a day.

Installing postgrey

Debian and Ubuntu have the package available in the main repositories.  On CentOS/RHEL based distros, you will need to enable the rpmforge repository per

Then just install postgrey with apt

apt-get install postgrey

Configure postgrey to start at boot:


update-rc.d postgrey defaults


chkconfig postgrey on

And tell it to start up (any distro):

/etc/init.d/postgrey start

Now, tell postfix to use it:

The package listens on localhost:10023 by default, so edit /etc/postfix/, and add ‘check_policy_service inet:’ to smtpd_recipient_restrictions.  Make sure to add it after permit_sasl_authenticated so you don’t greylist authenticated users.  Like this:

smtpd_recipient_restrictions =
        check_policy_service inet:

This package listens on a unix socket by default, so edit /etc/postfix/ and add ‘check_policy_service unix:/var/spool/postfix/postgrey/socket’ to ‘smtpd_recipient_restrictions.  Again, make sure to add it after permit_sasl_authenticated so as not to greylist yourself.  Example:

smtpd_recipient_restrictions =
        check_policy_service unix:/var/spool/postfix/postgrey/socket

Per-user greylisting

You can set it so that only particular users have their emails grey-listed.  e.g. in /etc/postfix/ have:

smtpd_restriction_classes = greylist
greylist = check_policy_service inet: 

And add the following to smtpd_recipient_restrictions in /etc/postfix/

    smtpd_recipient_restrictions =
            [other options that normally go here]
            check_recipient_access hash:/etc/postfix/greylist_optin 

(Note that you would have this set in smtpd_recipient_restrictions instead of the “check_policy_service unix:/var/spool/postfix/postgrey/socket” setting mentioned in the previous section.

In /etc/postfix/greylist_optin put users who should be greylisted followed by ‘greylist’ (the class defined above):    greylist     greylist

Sending mail to those users should now get greylisted (might need to ‘postmap /etc/postfix/greylist_optin’ before restarting postfix).

In /etc/postgrey/whitelist_clients you can add domains (domain names, one per line) that you think should not be greylisted.  e.g. domains of users that you deal with frequently (maybe avoiding common sources of spam though like,, etc).

Leave a Reply

Your email address will not be published. Required fields are marked *