For some weird reason, our postfix+spamassassin setup failed when multiple recipients were concerned. We moved our server a few weeks ago to a new platform (from Slackware to CentOS) and all versions were updated as well. I guess the problems arose there. In a typical postfix+spamassassin setup, you let postfix send all mail through an external filter (with the -o content_filter=<filter> in We had that same setup, with the difference, that we filter it all through a homebrew-script that also checks for a procmailrc file in the e-mails’ maildir. This procmailrc can then be programmed on a per-user basis on whether or not to throw the marked spam in a system-wide spambox, a local spambox, or in /dev/null. So far so good.

Until we found out, that e-mails that were to be delivered to more than one e-mail address, only got delivered to one. My first reaction was: “Huh?! I never changed that script and it worked fine on the old server.”. My second reaction was to login to my laptop, on the server, postpone my weekly running round and start hacking on the script. Turns out, the postfix ‘pipe’ filter will give you all the intended recipients as command line arguments. So, you’ll have to cycle over them to deliver all mail. Tricky part is that the e-mail itself (and you don’t want to lose that) is given on stdin. Oh, and we don’t want to scan an e-mail to multiple recipients, multiple times. Oh, and we certainly don’t want any mail that is deferred to the system-wide spamaccount to be scanned twice.

For now, the script is decent, but could use a few tweaks here and there. For example, instead of checking the target recipient to see if we scanned it already, we use the headers.

# BitTouch postfixfilter
# (c) 2010 BitTouch VOF
# This script takes the postfix arguments as input with an email in stdin


if [ $NUMRECIPIENTS -eq 1 -a "$4" = "<systemwidespamaccount>" ]; then
  SPAMRESULT="already scanned"
  THEMAIL=`/usr/bin/spamc -E`
  if [ "$?" = "1" ]; then

# The recipients start at argument 4, to the end
for ( (RECPT=4; RECPT<=$#; RECPT++) )
  if [ -f $PROCMAILRC ]; then
    echo "From: $SENDER, to: ${!RECPT} (spam: $SPAMRESULT): $PROCMAILRC exists, using that for delivery." >> $LOGFILE
    echo "$THEMAIL" | /usr/bin/procmail $PROCMAILRC
    echo "From: $SENDER, to: ${!RECPT} (spam: $SPAMRESULT): $PROCMAILRC does not exist. Deliver directly." >> $LOGFILE
    echo "$THEMAIL" | /usr/sbin/sendmail.postfix -i "$@"

exit 0
Categorieën: Geekstuff

1 reactie

Postfix and Spamassassin | Ik doe er niet aan mee · 10 maart 2010 op 6:15

[…] post:  Postfix and Spamassassin | Ik doe er niet aan mee Posted in Postfix | Tags: esmtp, from-gertie-apple-com, mta, new-platform, Postfix, pst, […]

Geef een reactie

Avatar plaatshouder

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.