SpamAssassin Under Exim 4.x

This page is now out of date and is no longer being updated. It’s left here for posterity, or until I can be bothered to take it down.

You will need:

Exim 4 (obviously!) from I assume you have a working installation of Exim and that you’re happy messing with exim.conf

Spamassassin from (2.60 or later essential if it’s to be of any use)

Download & install the latest version of SA. See
Start the SA spam daemon, spamd (this is more efficient than invoking Perl each time mail is delivered). You will want to add something to your startup files to invoke spamd if/when your box restarts.

Edit your Exim configuration as follows:

Add this to somewhere in your routers section (doesn’t matter where)

# SpamAssassin
driver = pipe
command = /usr/exim4/bin/exim -oMr spam-scanned -bS
use_bsmtp = true
transport_filter = /usr/local/bin/spamc
home_directory = "/tmp"
current_directory = "/tmp"
# must use a privileged user to set $received_protocol on the way back in!
user = exim
group = mail
log_output = true
return_fail_output = true
return_path_add = false
message_prefix =
message_suffix =

Add this to the top of the directors section:

# SpamAssassin
# When to scan a message :
# - it isn't already flagged as spam
# - it isn't already scanned
condition = "${if and { {!def:h_X-Spam-Flag:} {!eq {$received_protocol}{spam-scanned}}} {1}{0}}"
driver = accept
transport = spamcheck

Filtering Mail

All mail will now have a X-Spam-Status header attached to each email, allowing you to filter the spam either client side (e.g. in Outlook) or using Exim’s own inbuilt filters. I use Courier IMAP and in combination with a personal .forward file on the server, spam is simply dropped in my “Spam” folder.

# Exim filter <==DO NOT REMOVE!!

if error_message then finish endif

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