MTA: Exim

Spam check using SpamAssassin

by ross at 09:25:12 on April 27, 2017

Install SpamAssassin

# cd /usr/ports/mail/spamassassin
# make install clean
# cd /usr/ports/mail/sa-utils
# make install clean
# rehash

Add to /etc/rc.conf:

# Enable SpamAssassin

Initialize and start SpamAssassin:

# sa-update
# service sa-spamd start

Enable spam checks

Set spamd_address:

spamd_address = 783

Enable spam headers by adding this before final accept line in acl_check_rcpt ACL:

  warn    spam       = nobody                                                                                                                                             
          add_header = X-Spam-Score: $spam_score\n\                                                                                                                       
                       X-Spam-Level: $spam_bar\n\                                                                                                                         
                       X-Spam-Report: $spam_report                                                                                                                        

  warn    spam       = nobody                                                                                                                                             
          add_header = X-Spam-Flag: YES                                                                                                                                   
          condition  = ${if >{$spam_score_int}{30}{1}{0}}

Enable blacklist (optional) by adding this also before final accept line:

# deny using spamhaus
  deny message = Email blocked by SPAMHAUS. To unblock write to postmaster@ or visit
       # only for domains that do want to be tested against RBLs
       hosts = !+relay_from_hosts
       !authenticated = *
       dnslists =



Open test message and send it to your host from outside your network.

SpamAssassin reads its configuration in /usr/local/etc/mail/spamassassin directory For example, to add [SPAM] to header of spam messages add to

rewrite_header Subject [SPAM]

You can enable filtering by .forward files in Exim by uncommenting allow_filter in userforward router.

To save spam in its own folder create the following ~/.forward:

# Exim filter
  $h_X-Spam-Status: begins "Yes"
  "${if def:h_X-Spam-Flag {def}{undef}}" is "def"
    save $home/Maildir/.Spam