Articles‎ > ‎

Configuring SpamAssassin for Qmail

Configuring SpamAssassin for Qmail

1. Install SpamAssassin

=============================
yum install spamassassin
=============================

2. Install required perl modules

Run following command to get into cpan shell.

=============================
perl -MCPAN -e shell
=============================

Now, we can install perl modules.

==============================
install Mail::SpamAssassin
==============================

This will install "Mail::SpamAssassin" perl module.

Similarly, install following perl modules also.

=====================
Digest::SHA1
HTML::Parser
Net::DNS
Mail::SPF
Mail::SPF::Query
IP::Country
Net::Ident
IO::Socket::INET6
IO::Socket::SSL
Compress::Zlib
LWP::UserAgent
HTTP::Date
Archive::Tar
IO::Zlib
Encode::Detect
======================

3. Install qmail-spamc

3.1 Download SpamAssassin

===========================================================================================
cd /usr/local/src
wget http://www.alliedquotes.com/mirrors/apache/spamassassin/source/Mail-SpamAssassin-3.2.5.tar.gz
===========================================================================================

3.2 Extract SpamAssassin


=================================
tar -xzvf Mail-SpamAssassin-3.2.5.tar.gz

chown -R root.root /usr/local/src/Mail-SpamAssassin-3.2.5/
=================================

3.3 Compile qmail-spamc

============================================================
cd /usr/local/src/Mail-SpamAssassin-3.2.5/spamc

cc -O -o qmail-spamc qmail-spamc.c
============================================================

3.4 Install qmail-spamc

=================================================
install -m 755 qmail-spamc /var/qmail/bin
=================================================

4. Create soft link of qmail-queue

============================================================
ln -s /var/qmail/bin/qmail-queue /usr/bin/qmail-queue
============================================================

5. Allocate more memory to qmail-smtpd

I would recommend to increase the allocated memory of qmail-smtpd to 60MB

Edit /var/qmail/supervise/qmail-smtpd/run

==========================================================================================
LOCAL=`head -1 /var/qmail/control/me`

if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
    echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
    echo /var/qmail/supervise/qmail-smtpd/run
    exit 1
fi

if [ ! -f /var/qmail/control/rcpthosts ]; then
    echo "No /var/qmail/control/rcpthosts!"
    echo "Refusing to start SMTP listener because it'll create an open relay"
    exit 1
fi

exec /usr/local/bin/softlimit -m 60000000 \
    /usr/local/bin/tcpserver -v -R -l "$LOCAL" -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1
===========================================================================================

6. Configure TCP server

6.1 Modify /etc/tcp.smtp file as given below.

================================================================
      127.:allow,RELAYCLIENT=""
      :allow,QMAILQUEUE="/var/qmail/bin/qmail-spamc"
================================================================

6.2 Update TCP rules database using following command.

=============================
qmailctl cdb
=============================

Now, spam checking will be done on all emails from remote servers.

7. Start spamassassin

=========================
/etc/init.d/spamassassin start
=========================

Done !

Reference

1. http://commons.oreilly.com/wiki/index.php/SpamAssassin/Integrating_SpamAssassin_with_qmail




Comments


1. Name:         James Hawker   

Thanks for your article on configuring spamassassin to work with qmail.

I have just one comment though - Everything is correct but in the /var/qmail-smtp/run file the line

QMAILQUEUE="/var/qmail/bin/qmail-spamc"; export QMAILQUEUE

needs to be added also.

Again thanks for the tip


Comments