Sendmail + Procmail + Spamassassin + Cyrus + Sieve

I’ve always used sendmail and qpopper. It wasn’t until recently that I made the switch to imap. Getting server-side filtering was a real pain in the ass, and documentation for several of these packages is sparse to say the least. Hopefully this will point you in the right direction. This will be easiest to use if you’ve already got sendmail and cyrus working together. Please drop a comment if you see a mistake or have a suggestion as to how to make this howto more admin-friendly.

You should have sendmail installed and configured to your liking before continuing. I’ll gloss over the sections where more documentation can easily be found. Start by installing procmail and adding it to sendmail as follows:

## file: /etc/mail/sendmail.mc ##

define(`PROCMAIL_MAILER_PATH’,`/usr/bin/procmail’)dnl

FEATURE(local_procmail,`’,`procmail -t -Y -a $h -d $u’)dnl
MAILER(local)dnl
MAILER(smtp)dnl

Get formail if it’s not already installed. It’s used here to fix the headers after procmail modifies them. spamcheck.py can be found in the spamassassin 2.6x contrib (it works fine with 3.x). You may have found another shell script for spamassassin and cyrus that uses cyrus deliver. That configuration is fine if you don’t plan to do server-side sieve filtering.

## file: /etc/procmailrc ##
DROPPRIVS=no
:0fw
| /usr/bin/formail -I”From “|/usr/local/bin/spamcheck.py -s nobody -r $LOGNAME -l unix:/var/imap/socket/lmtp

Get spamassassin installed and listening on localhost.

Install cyrus and setup the sieve daemon and lmtp socket:

## file: /etc/cyrus.conf ##

sieve cmd=”timsieved” listen=”localhost:sieve” prefork=0
lmtpunix cmd=”lmtpd” listen=”/var/imap/socket/lmtp” prefork=0

## file: /etc/imapd.conf ##
configdirectory: /var/imap
partition-default: /var/spool/imap
sievedir: /var/imap/sieve
# sieveusehomedir: yes
hashimapspool: yes
allowanonymouslogin: no
altnamespace: 1
lmtpsocket: /var/imap/socket/lmtp

Uncomment the `sieveusehomedir’ setting if you’re looking to use .sieve files in the users’ home directories. If this is your first time using sieve it may help to know that they have to be compiled. I’m using squirrelmail’s sieve plugin to update the sieve scripts. Since it connects to the sieve daemon, everything is done automatically. If you’re using .sieve, use the sievec binary to compile your scripts.

Restart all your daemons and pray.

One Response to “Sendmail + Procmail + Spamassassin + Cyrus + Sieve”

  1. August 30th, 2005 | 6:14 am

    Outstanding synopsis. Just a couple of notes:

    The default install for imap on my Fedora Core 4 installation at least is /var/lib/imap. Be wary of this when making the changes to /etc/procmailrc, /etc/cyrus.conf and /etc/imapd.conf.

    The current build of Spamassassin (3.0.4) does not contain the spamcheck.py script. The older build 2.6x scripts work fine. The following wgot the two python scripts into the right location:

    # cd /usr/local/bin
    # wget http://spamassassin.apache.org/full/2.6x/dist/contrib/spamcheck.py
    # wget http://spamassassin.apache.org/full/2.6x/dist/contrib/spamd.py
    # chmod g+x spamcheck.py spamd.py

    Finally, if you were running Cyrus with sendmail previously, make sure you remove ALL references to Cyrus from sendmail.mc before rebuilding the config.

    Everything else worked like a dream. Thanks again.

Leave a reply