SpamAssassin made simple with Postfix

Simple instructions how to make SpamAssassin tag spam with Postfix.

Install spamd and spamc

Debian:
  1. apt-get install spamc spamassassin
  2. add extras what apt-get suggests if you want to, but you don't need to.
  3. edit /etc/default/spamassassin and set 'ENABLED=1'.
  4. /etc/init.d/spamassassin start

Make new user

useradd -m spam

Install script

cat >/home/spam/spam.sh <<"EOF"
#!/bin/sh
 
file=/home/spam/.spam-tmp$$
spamc -x >$file || exit 75
/usr/sbin/sendmail <$file -i "$@" || exit 75
rm $file || exit 75
EOF

chmod +x
/home/spam/spam.sh

Edit master.cf

[...]
# ============================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ============================================================================
smtp inet n - n - - smtpd
-o content_filter=spam:
[...]
spam unix - n n - - pipe
flags=Rq user=spam argv=/home/spam/spam.sh -f ${sender} -- ${recipient}
[...]

Add bolded parts.

Restart postfix

Better do 'postfix stop' and 'postfix start'. Watch that mail flows smoothly: tail -f /var/log/mail.log. Instruct users to to filter spam with help of 'X-Spam-Flag: YES' header.

Any questions? Mail me: Petri T. Koistinen <petri.koistinen@iki.fi>
last modified: Sunday, 07-Sep-2008 00:09:44 EEST