VestaCP spamassasin and exim4 fix

This is a short post that id like to share since i couldnt find the info in vestacp documents.

Vesta control panel is a very nice and easy to use open source control panel with website, email, database, and DNS functionalities built in.

If you wish to find out how to install it just follow this guide.

Then the following is necessary to enable spamassasin and clamd

How to install ClamAV and SpamAssassin on a Debian or Ubuntu for VestaCP

Make sure you have enough ram available on your system.3gb is recomended but if you only have a few users you can get away with much less.

ClamAV installation

 apt-get install clamav-daemon
 wget http://c.vestacp.com/0.9.8/ubuntu/clamd.conf -O /etc/clamav/clamd.conf
 gpasswd -a clamav mail
 gpasswd -a clamav Debian-exim
 freshclam
 update-rc.d clamav-daemon defaults
 service clamav-daemon restart

SpamAssassin installation

apt-get install spamassassin
 update-rc.d spamassassin defaults
 sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
 service spamassassin restart

Exim configuration

sed -i "s/^#SPAMASSASSIN/SPAMASSASSIN/g" /etc/exim4/exim4.conf.template
 sed -i "s/^#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
 service exim4 restart

Vesta configuration

sed -i "s/ANTIVIRUS.*/ANTIVIRUS_SYSTEM='clamav-daemon'/" /usr/local/vesta/conf/vesta.conf
 sed -i "s/ANTISPAM.*/ANTISPAM_SYSTEM='spamassassin'/" /usr/local/vesta/conf/vesta.conf

Fix exim4 configuration

The issue you will have is after you install spamassasin, it simply wont work as it should. The header on emails that are spam wont be affected and you wont know what is being blocked.

You need to go into file /etc/exim4/exim4.conf and modify the text under ACL CONFIGURATION to the following

.ifdef SPAMASSASSIN

  warn
    spam = debian-spamd:true
    add_header = X-Spam_score: $spam_score\n\
              X-Spam_score_int: $spam_score_int\n\
              X-Spam_bar: $spam_bar\n\
              X-Spam_report: $spam_report

  deny
    message = This message scored $spam_score spam points.
    spam = debian-spamd:true
    condition = ${if >{$spam_score_int}{120}{1}{0}}



.endif

The way exim4 and spamassain work on vestacp is that emails go to exim then to spamassasin then back to exim4.

So what this part of the configuration file does is if the spamscore exists the score stated in the begining of the /etc/exim4/exim4.conf (which by default is "SPAM_SCORE = 50" ) then modify the header and add to it the score.

The second part under the "deny" returns the message to the sender if the score is above 120.

You can further play with rules here to more complex configurations. A nice guide i found is here