Mail The Unix Way - Procmail
Summary:- Basics
- Setting Basic Variables
- Writing Recipes
- The Sky Is The Limit
Basics
'Procmail' is the standard mail processing program on Mandrake Linux when using the Postfix MTA. Although it is the most powerful application for this kind of tasks, its configuration syntax can be quite daunting. If you consider using an other program for filtering your mail, you have to adapt themailbox_command =
man procmailex
man procmailrc
- Each recipe searches for one or more specified characteristics on each incoming mail.
- If a message matches the specified criteria in a recipe, the filter or command listed in the recipe is applied to the message. If not, the message is passed on unchanged to the next recipe.
- A matched message may either be removed from the incoming mail queue or be processed further by other recipes.
- If an incoming message doesn't match any recipe, it will be delivered unchanged into the default mailbox.
Setting Basic Variables
Start your '.procmailrc' by setting some variables:PATH=/usr/bin:/bin:/usr/local/bin:/usr/X11R6/bin<br> MAILDIR=$HOME/Mail<br> DEFAULT=$MAILDIR/inbox<br> PMDIR=$HOME/tmp/procmail<br> LOGFILE=$PMDIR/log
- : Since you may run programs from .procmailrc, tell it where it may find them.
PATH
- : The name of the directory where your mail folders or files are or should be.
MAILDIR
- : The name of the directory or file where all mail which doesn't match a recipe will be stored in (the 'inbox').
DEFAULT
- and
PMDIR
: Where to put 'Procmail's' logging file. This file is very useful for examining how your recipes work or why they do not work.LOGFILE
Writing Recipes
A simple recipe may look like this::0:<br> inbox
:0:<br> ~* ^From.*alice<br> wonderland
- This is a new recipe.
- Look for this condition (
- wouldn't work. This would look for a string "Fromalice" in the header of the message. The "From" and the sender's name must be separated.
* Fromalice
- would also match a subject like "This stems from malice". You need to tell 'Procmail' that you expect the "From" at the beginning of a header line (^). To make the rule even tighter, you also tell 'procmail' that this string "From" must be followed by exactly one character (.), usually that's ':'.
* From*alice
- would be bad because the matching line would have to look like this "From:Alice {etc}". "From: Alice {etc}" wouldn't match (more than one character between "From" and "Alice") and "From:
* ^From.alice
This is quite handy since it allows you to put all messages which are addressed or Cc'ed to you in a special folder. Put something like
:0:<br> ~* ^TO_{your mail address}<br> inbox
The ^TO_ macro is especially useful for handling mailing lists:
:0:<br> ~* ^TO_newbie<br> newbie
man procmailex
MONTHFOLDER=$(date +%y-%m)<br> <br> :0 Wic<br> ~* ? test 1.1 -d $MONTHFOLDER<br> | mkdir $MONTHFOLDER<br> <br> :0:<br> ~* meeting<br> ${MONTHFOLDER}/meeting
You see? This sorts your mail automatically into folders named after the current month. At the beginning of every new month, a new folder is created. I advise you strongly to test your rules internally by sending local mail which matches the specified criteria to your own account. A 'simple' MUA like
mutt
The Sky Is The Limit
'Procmail' can not only filter mail, but also copy it, forward it, bounce it, create auto-replies and 'away' messages, act as a spam filter, sort mail according to date, size and so on. Recipes can be nested, you can change the default settings and make 'Procmail' searching for matching strings in the emails body, strip HTML attachments or VCards and weed out duplicate mail. You can spend quite some time configuring it ;-). If you want to get an impression how vast this is, get Jari's pm-tips. Be forewarned though, this a 650 KB text file :-) section indexRelated Resources:
Procmail homepageFiltering Mail FAQ
Procmail FAQ
Procmail Quick Start
man procmailex
Author: Tom Berger Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.
Mail The Unix Way - Procmail
Version 1.3 last modified by AdminWiki on 22/03/2004 at 09:44
Version 1.3 last modified by AdminWiki on 22/03/2004 at 09:44
Document data
- Lost account?
- Join the community, be part of the Club: it's free!
- Get the PWP Download Subscription!
Mandriva.com
Store
Club

