Using procmail to sort mailing lists

Wed Mar 8 21:15:43 MYT 2000

Procmail is a free opensource package that can automatically process messages as soon as they arrive. This guide will only attempt to inform one how to forward mail to other folders - hence lead one to having a very organised mailbox.

For the purpose of this guide, the RedHat Linux 6.0 distrubution is the choice (6.0 an up will work fine, since a .forward file doesn't need to exist). Hence, you will need to have you mail messages delivered to a Linux (Unix is fine) system that:

Now, the procmail primer can begin!


  1. Locate procmail (in a console, type locate procmail, whereis procmail or even type procmail). Check www.procmail.org for the latest version of procmail (RedHat ships with a fairly working version).
  2. Create your ~/.procmailrc and enter the following. Remeber, that # means that its a message, and will not get processed.
    # Upon debugging, you want verbose, you make it yes
    VERBOSE=no
    
    # Upon debugging remove the #
    # LOGABSTRACT=all
    
    # Replace $HOME/mail with whatever it is your mail directory is
    MAILDIR=$HOME/mail # This is the default for pine
    
    # Directory for storing procmail items
    PMDIR=$HOME/Procmail # Create this directory on your system for recipe files
    
    LOGFILE=$PMDIR/log
    INCLUDERC=$PMDIR/test.rc
    INCLUDERC=$PMDIR/lists.rc
    
  3. Create the test.rc file in ~/Procmail, then enter the following into ~/Procmail/test.rc:
    :0:
    * ^Subject:.*testing
    testing
    
    Note that the first line is a zero (0), not an O.
  4. You're set to go. Try testing procmail. Send yourself a message with testing in the subject line, and then later send yourself another message without testing in the subject line.
  5. Fire up your mail client. You'll see one message in your Inbox, and if you check your other folders, a folder called testing would have been created with the other message in there.
    If they were delivered correctly, congratulations! If they were not, you can:
  6. Edit the ~/.procmailrc file and add the # in front of the INCLUDERC=$PMDIR/test.rc, since it will no longer need to process the recipe any longer. You can even delete this line, since there should be no need for its existience.
  7. Now, time to create ~/Procmail/lists.rc to sort mailing lists (the main purpose of this guide). Have a recipe created for one list, such as:
    :0:
    * ^TO_myoss@my-opensource.org
    list-myoss
    
    The above recipe puts all messages sent to myoss@my-opensource.org into a folder called list-myoss in ~/mail (as defined in your .procmailrc file). Here are some notations to utilise in your recipe files.

    :0 Begin a recipe
    :0: Begin a recipe and use a lock file (this will help prevent mail handling errors)
    * Begin a condition
    ^TO_ Look for a header that begins with To: or Cc:, followed by an e-mail address that has a string
    myoss@my-opensource.org The said mailing list
    list-myoss If a match exists, the mail is moved over to this folder

    Note: As a tip, it is advised that the busiest of mailing lists be placed on the top of your lists.rc file - this helps it process faster, saving your CPU cycles.

    That should actually fix everything that you wanted. Now, all mailing lists will be sorted, and you can finally get your mailbox to yourself. This setup works especially well when you start fetching mail from various accounts, like when you use fetchmail (read Getting fetchmail to work with IMail to see what kind of setup I utilise).

    Link Farm

    These URL's just may come in handy, if you want it to work a little harder.
    Geek Documents | bytebot.net