Top Nav

Postfix + Spam Assassin + ClamAV on RHEL

Some notes on setting up a Postfix server to use ClamAv and SpamAssassin. Follow the steps below to set this up on a normal Redhat box with a default Postfix setup. See step 8 for a bonus trick with header_checks to enable spam deletion.

1) Create two service accounts (set shell to /bin/false):

2) Install the latest ClamAV. Configure it to run as the “clamav” user (which is the default I think). Add “/usr/local/sbin/clamd” to rc.local. Find the clamd.conf (defaults to /usr/local/etc or /etc), and make the following settings:

Also update freshclam.conf (the Example line has to be commented out in it as well), run freshclam and add a cron job to run freshclam on a regular basis. Start clamd before proceeding to step 3.

3) Download and install a package called clamsmtp ( No configure options needed. After doing the make install, create /usr/local/etc/clamsmtpd.conf with the following contents:

In the package source, copy the file scripts/ to /etc/init.d/, and add “/etc/init.d/ start” to rc.local. Go ahead and start clamsmtpd.

4) Create a file, /usr/local/bin/ with the following contents:

Chmod 755 the script, and chown it to spamfilter.spamfilter

5) Make sure SpamAssassin is installed, and configured to start up on boot (chkconfig spamassassin on). Start /etc/init.d/spamassassin if it isn’t already running. Configure /etc/mail/spamassassin/ as desired.

6) Edit the file /etc/postfix/ Find the first “smtp” line at the top. It will look like this:

Add the following options to the end of that line:

Next go to the bottom of the file, and add all of the following lines (everything between the –snip–‘s):

Save out, and restart Postfix (/etc/init.d/postfix restart).

7) If the gods favour you, and if I haven’t forgotten something, then you’ll now have ClamAV and SpamAssassin filtering in effect.

8) One additional step that may be desired is to have Postfix drop messages that score above some threshold in SpamAssassin. In /etc/mail/spamassassin/ you specify the required score for a message to be flagged as spam, but SpamAssassin itself can’t delete the message, only modify it. So set with a “low” score to modify the subject line, and do this next step to set a “high” score which will result in deletion:

Edit /etc/postfix/, and add this line (check to make sure it doesn’t already exist):

Save out, and then edit /etc/postfix/header_checks, and add the following line to the bottom:

This check looks at the X-Spam-Level header that SpamAssassin inserts. Each * in the header represents a score level. So 10 stars means the message scored a 10 (or at least, the rounded off score is 10). This check will match the header if it has 10 or more stars, and will discard it and log the optional text after DISCARD. You can use “REDIRECT” instead of DISCARD if you want to send the spam somewhere instead of deleting it.