Howto Qmail with spamassassin

By Sylvestre Ledru June 2003
Version francaise
Return to the linux page

New (01/11/2003), Qmail-scanner :
I had a new way of calling spamassassin client using qmail-scanner.
New (23/07/2003), Preferences :
Matthew Francis sent me a quite good howto explaining how to get user preferences for spamassassin. It is available here.
New (08/06/2003), Localisation :
If you want to change the language of the spam report (ie why the email has been tagged as a spam), just change the locales to your language (dpkg-reconfigure locales under debian) and install gettext (apt-get install gettext) and you will have the appropriate version (french for example)...

If you like this howto and you want to thank me for my work : here is my wishlist on Amazon - France or my Amazon US wishlist


If you want more informations about the intallation of qmail, I wrote a long howto about.
I wrote this howto because there is a lack of documentation about qmail with spamassassin.

This howto has been designed for qmail with vpopmail but it should work without a lot of modifications with something else than vpopmail.

Spamassassin is a very powerfull program which checks if the receveid email is a spam or not. The analys is based on a list of mark. If the sum of all the mark exceed a specified amount (for example 5), the email will be tagged (****SPAM**** in the topic).
With this, it is very easy to create a rule which will move all emails into a specific directory (i.e. trash:)

If you want to link Qmail with spamassassin, it is quite easy.
First, install spamassassin and install razor and pyzor if you want to use it.

Under debian :

apt-get install spamassassin You should use the "debian unstable or testing" version of spamassassin which, most of the time, will find more spam.



Under other system (Redhat, Suse, Solaris ...) :

wget http://useast.spamassassin.org/released/Mail-SpamAssassin-2.55.tar.gz
tar -zxvf Mail-SpamAssassin-2.55.tar.gz
cdd Mail-SpamAssassin-2.55
perl Makefile.PL
make
make install
cp spamd/debian-rc-script.sh /etc/init.d/spamassassin You can replace debian by redhat, solaris, netbsd, suse ...
chmod +x /etc/init.d/spamassassin



Then, edit /etc/spamassassin/local.cf

required_hits 6.0
rewrite_subject 1
report_header 1
use_terse_report 1
defang_mime 1
dns_available yes
dcc_add_header 1
use_pyzor 1 (Only if you have installed pyzor)
use_razor2 (Only if you have installed razor2)
use_dcc 1

If you want to have detailled information about spamassassin processing, add the line in the local.cf file : timelog_path /var/log/spamassassin, create the directory with appropriate rights (should be vpopmail). In the directory, you will have for each email a file which sum up the spamassassin process (it is a debug option !).

I use these rules. Feel free to change ! Documentation about this is available here : perldoc Mail::SpamAssassin::Conf

In /etc/default/spamassassin (if this file does not exist, create it)
Change ENABLED to 1, then add these options to "-m 10 -v --auto-whitelist".
With that stuff, you can launch spamd which is bascilly a spamassassin deamon (provide great performances).
-m 10 => 10 childs
-v => vpopmail config
--auto-whitelist => Use auto whitelist (friend list)
Instead of spamassassin, you have to use spamc in order to test email.
There are some options "-c -u vpopmail" which enabled the creation of preferences for a domain or a user but it does not work very well for me.
/etc/init.d/spamassassin start


Next, the modification of qmail in order to check emails.
Basically, there are two kind of configuration for qmail :
- the fastest/easiest way is to change the qmail-queue in order to "introduce" the spamasssin check.
- the cleanest way is to use qmail-scanner.

Changing the qmail-queue program

cp /var/qmail/bin/qmail-queue /var/qmail/bin/qmail-queue.orig
chown -R qmailq:qmail qmail-queue
chown -R qmailq:qmail qmail-queue.orig
chmod u+s qmail-queue.orig
chmod o+r qmail-queue.orig qmail-queue Not fundamental but sometime it is necessary (depends the system)

mkdir /home/vpopmail/.spamassassin
cd /home/vpopmail
chmod 777 /home/vpopmail/.spamassassin

chown -R qmailq:qmail .spamassassin
chmod u=rwx,g=rx,o= /home/vpopmail/.spamassassin

Now, delete the content of the executable which manage the queue.

echo -n > /var/qmail/bin/qmail-queue

Then, edit the qmail-queue file and add this inside :

#!/bin/sh
/usr/bin/spamc | /var/qmail/bin/qmail-queue.orig


With qmail-scanner

First, you have to patch qmail with the qmailqueue-patch.

wget http://qmail.agarik.com/qmail-1.03.tar.gz
tar -zxvf qmail-1.03.tar.gz
cd qmail-1.03
wget http://qmail.mirrored.ca/moni.csi.hu/pub/glibc-2.3.1/qmail-1.03.errno.patch
wget http://sylvestre.ledru.info/howto/qmail/qmailqueue-patch
patch -p1 < qmail-1.03.errno.patch
patch -p1 < qmailqueue-patch

Add the QMAILQUEUE parameter to the /etc/tcp.smtp file :

127.0.0.1:allow,RELAYCLIENT="",QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl"
198.168.1.:allow,RELAYCLIENT="",QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl"
:allow,QMAILQUEUE="/var/qmail/bin/qmail-scanner-queue.pl"

Rehash tcpserver :

/usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
chmod 644 /etc/tcp.smtp.cdb

And then, install qmail-scanner :

wget http://unc.dl.sourceforge.net/sourceforge/qmail-scanner/qmail-scanner-1.20rc3.tgz
tar -zxvf qmail-scanner-1.20rc3.tgz
cd qmaail-scanner-1.20rc3/
groupadd qscand
useradd -c "Qmail-Scanner Account" -g qscand -s /bin/false qscand
./configure --spooldir /var/spool/qmailscan --qmaildir /var/qmail --bindir /var/qmail/bin --qmail-queue-binnary /var/qmail/bin/qmail-queue --admin postmaster --domain vladimir.avence.info --notify sender,admin,recips --local-domains vladimir.avence.info --siilent-viruses auto --lang fr_FR --debug 1 --unzip 1 --add-dscr-hdrs 1 --archive 0 --redundant no --log-details yes --log-crypto 0 --fix-mime 1 --scanners "ffast_spamassassin" --install 1 Change vladimir.avence.info for your host

After the installation, if you want to change your preferences, you have to edit the /var/qmail/bin/qmail-queue-scanner.pl file. In this file, you can also add option for the spamassassin client.

This should be enough to use SpamAssassin on the whole system.
I have to try to find how it can be linked with vpopmail in order to create preference for a specific domain or a specific user. (if some knows : sylvestre@ledru.info)

Problems :
- link with vpopmail
This howto is inspired and corrected from :
http://www.euronet.nl/users/erhnam/linux/qmail/qmail.htm.

From :kevin binsfield (kbinsfie_at_rocketmail.com) posted on 04/12/2003 15:40
Comment :
Under install qmail-scanner-

./configure for english directions says to configure langauge in French. Since you have in red test to change domain name, add to change language preference.

 
From :Sean Treadway (seant.at.oncotype.dk) posted on 12/12/2003 12:04
Comment :
The way we setup spamassassin to be active for a single vpopmail domain is to add spamc to the pipeline in the .qmail-default file located in the vpopmail domain directory.

| /usr/local/bin/spamc -t 45 | /usr/local/vpopmail/bin/vdelivermail '' bounce-no-mailbox

This will check spam for all incoming mails without modification of the base qmail system. We trust all outgoing mails so we don't need to check them when they are queued.
 

Add a comment :
Author :
Email :
Comment :