# Postfix & spamassassin & procmail setup and theory

## MacMasta

I've done extensive google and forum searching on this, and it hasn't quite made sense yet, so here goes:

I've got a little machine that recieves and sends mail using postfix, and I want to set up spam filtering (using spamassassin) and folder re-direction and such (procmail).

The "pipeline" should look like this, as I understand it:

mail comes into system -> postfix -> procmail -> spamassassin -> procmail (for the rest of the filtering) -> ~/.maildir

I see that main.cf for postfix has a "mailbox_command" function that suggests procmail - and I know that I can call spamassassin from procmail very easily. However, every user should have their own ~/.procmailrc, right? How do I configure postfix's mailbox_command to make sure it uses the .procmailrc of the user who is receiving the mail? 

I assume that I'll need to tell procmail to put things in pine's mail directory, not into directories in ~/.maildir - but that can't be too hard.

Is my understanding of the process sound? How do I correctly configure postfix?

Corollary(sp?) question: I'll be using an almost identical setup on another machine, but with fetchmail/getmail getting mail from pop3 accounts.

Does the order of events on that system look like:

1) getmail -> postfix -> procmail -> spamassassin -> procmail -> ~/.maildir

or does getmail/fetchmail bypass postix (which would require me to call procmail from .fetchmailrc or .getmailrc somehow), and result in:

2) getmail -> procmail -> spamassassin -> procmail -> ~/.maildir.

?

Thanks for the help!

~Mac~

----------

## fyerk

I think the easiest way to do this is to have procmail as the mailbox command and then pipe incoming email through SpamAssassin on a per user basis.

/etc/postfix/main.cf

```

mailbox_command = /usr/bin/procmail

```

$HOME/.procmailrc

```

# Procmail Recipie File

DEFAULT="$HOME/.maildir/"

MAILDIR="$HOME/.maildir/"

# Spam Detection

SPAM_FOLDER="$HOME/.maildir/.spam/"

:0 fw

| /usr/bin/spamc -f

:0

* X-Spam-Status: Yes

$SPAM_FOLDER

```

Note that this assumes you're using Maildir style mailboxes (e.g. Courier-IMAP).

This also requires SpamAssassin to be running as a daemon, so you'ld need to run the following commands to start it and make sure it starts on reboot.

```

# /etc/init.d/spamd start

# rc-update add spamd default

```

----------

