Why

The grey listing consist to temporarily reject the first message received from an unknown sender, and according to the SMTP protocol the sender must try again later.

This greatly improves spam detection, because from the message rejection there are two possible ways for the sender:

  • not sending the message again, and in this case, it is certainly a person who is doing mass mailing
  • sending the message again, and if it’s spam, the elapsed time will have permited updating of the blacklists like spamcop or spamhaus. These blacklists can be exploited by spamassassin or directly by postfix.
See also
Build information

Ensure the following options:

mail/sqlgrey
[x] MYSQL              MySQL backend

Configuration

The configuration file sqlgrey.conf is located in the /usr/local/etc/sqlgrey/ directory.

sqlgrey process and network connection
loglevel             = 2
unix                 = /var/run/sqlgrey.sock
pidfile              = /var/run/sqlgrey.pid
admin_mail           = postmaster
Information to access and manage the database
db_type              = mysql
db_name              = Database name
db_host              = 127.0.0.1
db_user              = Database user
db_pass              = Database user password
db_cleandelay        = 1800
Management of grey listing
connect_src_throttle = 10
awl_age              = 50
group_domain_level   = 5
greymethod           = smart
optmethod            = optout
discrimination       = off
prepend              = 1

Initialisation

-- Create databse
CREATE DATABASE Database name CHARACTER SET latin1;
-- Grant access
GRANT ALL ON Database name.* 
          TO 'Database user'@'localhost' IDENTIFIED BY 'Database user password'

Whitelist

Unfortunately not all legit mail servers respect the rules, and it is necessary to have a whitelist for some of them, either based on the IP address clients_ip_whitelist or on the fully qualified host name clients_fqdn_whitelist.

The clients_ip_whitelist and clients_fqdn_whitelist files can be automatically updated using:

Update whitlists
update_sqlgrey_config

If you need to manually specify additional servers you need to use:

Startup

sqlgrey_enable="YES"

Integration

Postfix

It is used with the check_policy_service action from the /etc/postfix/main.cf configuration file, for example:

smtpd_recipient_restrictions =
               ...
               check_policy_service unix:/var/run/sqlgrey.sock
               ...

When adding the check_policy_service for sqlgrey, be careful where you place it according to other existing rules