Procmail

From LQWiki
Jump to navigation Jump to search

Procmail is a filtering program that processes your email, e.g. it can feed it to SpamAssassin or move it to the appropriate folders. It should be invoked automatically when mail arrives. Procmail can be configured via /etc/procmailrc.

Procmail statements fall in one of two categories:

  • assignments like LOGNAME=/var/log/procmail
  • rules for filtering


Test your procmail

To see if your procmail works, try the following:

echo "This will be in your mailbox" | procmail

Then look if the text is in your mailbox, e.g.:

cat /var/spool/mail/root

or if you use MailDirs to store your mails:

cat ~/Maildir/new/*

By this command, you should also be able to verify if your procmail calls SpamAssassin:

X-Spam-Checker-Version: SpamAssassin 3.1.4 (2006-07-25) on scorpio.site
X-Spam-Level: ***
X-Spam-Status: No, score=3.2 required=5.0 tests=EMPTY_MESSAGE,MISSING_HEADERS,
        MISSING_SUBJECT,NO_RECEIVED,NO_RELAYS,TO_CC_NONE autolearn=no
        version=3.1.4
This will be in your mailbox

Examples

The following can go into /etc/procmailrc

LOGNAME=/var/log/procmail
DROPPRIVS=yes
DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir/

#Forward mail to spamassassin
:0fw
| /usr/bin/spamc

#Move mail marked as spam to a Spam mailbox
:0:
* ^X-Spam-Level: \*\*\*
.Trash/

:0:
* ^X-Spam-Status: Yes
.Trash/

Moves all your spam to the .Trash folder must be a Maildir, procmail does not support /var/mail/USERNAME

Configure your procmail

Best, configure your procmail with webmin that has a module for doing that.

See also