SpamAssassin + Postfix to Deliver Spam to an Alternate Mailbox

Posted on April 10th, 2009 in General,Linux System Administration,Mail,Spam by Brandon

A fairly simple method of having postfix send messages through SpamAssassin, and then delivering the messages identified as spam to a separate mailbox:

Configure SpamAssassin as normal in master.cf:

smtp      inet  n       -       -       -       -       smtpd -o content_filter=spamassassin
2525      inet  n       -       -       -       -       smtpd -o content_filter=spamassassin
spamassassin unix -     n       n       -       -       pipe user=spamd argv=/usr/bin/spamc -f -e    /usr/sbin/sendmail -oi -f ${sender} ${recipient}

Configure Spamassassin to log the status and score in a new header by adding this to /etc/spamassassin/local.cf:

## Add a spamassassin header to all messages so that we can filter them out
add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ tests=_TESTS_ autolearn=_AUTOLEARN_ version=_VERSION_

And then configure postfix to look for that header and deliver it to an alternate mailbox:

/etc/postfix/main.cf:

header_checks = regexp:/etc/postfix/header_checks

/etc/postfix/header_checks:

/^X-Spam-Status: Yes/ REDIRECT spam@yourdomain.com

Now your messages identified as spam will be sent to spam@yourdomain.com so that you can occasionally check for false positives.

Note that there is more work that goes into setting up SpamAssassin, but there are plenty of howtos around for getting that configured.

One Response to 'SpamAssassin + Postfix to Deliver Spam to an Alternate Mailbox'

Subscribe to comments with RSS or TrackBack to 'SpamAssassin + Postfix to Deliver Spam to an Alternate Mailbox'.

  1. Johny said,

    on June 8th, 2009 at 9:48 am

    Is it possible to redirect to different targets based on originaly targeted domain?

Post a comment

Please copy the string SErNFE to the field below: