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

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/

## 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:


header_checks = regexp:/etc/postfix/header_checks


/^X-Spam-Status: Yes/ REDIRECT

Now your messages identified as spam will be sent to 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?

  2. Alex said,

    on August 31st, 2015 at 6:28 pm

    Perfect. Just what I was looking for, thanks!

Post a comment