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
spamd_enable="YES"

Initialize and start SpamAssassin:

# sa-update
# service sa-spamd start

Enable spam checks

Set spamd_address:

spamd_address = 127.0.0.1 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 [email protected] or visit http://www.spamhaus.org/lookup.lasso
       # only for domains that do want to be tested against RBLs
       hosts = !+relay_from_hosts
       !authenticated = *
       dnslists = zen.spamhaus.org

  accept

Testing

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 local.cf:

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
if
  $h_X-Spam-Status: begins "Yes"
  or
  "${if def:h_X-Spam-Flag {def}{undef}}" is "def"
then
    save $home/Maildir/.Spam
    finish
endif

 

Comments