Quick Procmail Setup

Procmail is an all-purpose mail filtering program. See this procmail page for more information.

Setup files and directories

Note: When a file named .procmailrc is created, the system procmail program will start working for you, so do this last. All other files and directories can be names of your choosing.

First, create a procmail directory, which will contain a rules file for mail filtering rules, and a procmail log file. Then create a mail directory to hold filtered mail.

mkdir ~/.pmdir
touch ~/.pmdir/log
touch ~/.pmdir/rules
touch ~/.procmailrc

mkdir ~/mail/.inboxes touch ~/mail/.inboxes/INBOX touch ~/mail/.inboxes/work touch ~/mail/.inboxes/mac touch ~/mail/.inboxes/personal

Create Filtering Rules

Now use a text editor to enter some filtering rules.

~/.pmdir/rules
# I like to keep rules in a separate file
# Be careful with the regular expressions, read the man page for specifics

# append any mail from apple.com into the file mac :0: * ^FROM:.*apple.com* mac

# append any mail sent to labs into the file work :0: * ^TO:labs work

# delete mail from these spammers :0 * ^FROM:.*(spam.com|spamsenders) /dev/null

:0: INBOX

Create .procmail file

This is the file that makes everything start happening, so don't create it until everything else is in place.

~/.procmailrc
# Set on when debugging
VERBOSE=on

# Directory where procmail defaults to put new mail files MAILDIR=$HOME/mail/.inboxes DEFAULT=$HOME/mail/.inboxes/

# Directory for storing procmail log and rc files PMDIR=$HOME/.pmdir

LOGFILE=$PMDIR/log

# by default, the rules are in the current file # this tells procmail to get them elsewhere INCLUDERC=$PMDIR/rules

You will have to configure your mail reader to point to the new filtered mail files.

Debugging

Check the log file to see where messages are getting dumped. If you suspect procmail is messing something up, turn it off by renaming .procmailrc (and .forward if you are using it), so that procmail won't find them.

mv .procmailrc .procmailrc-testing

If the log file indicates that procmail is doing what you want it to, then turn off verbosity by editing the .procmailrc file, but make sure to watch the log file closely until you trust the setup. Be sure to remove the log file now and then if it starts to get too big