You have been redirected here, which houses content from our former website; this content may or may not be current. Our official website may have more up-to-date information.
UBC Mathematics: MathNet FAQ [Mail Filtering]

UBC Mathematics: MathNet FAQ [Mail Filtering]

Question: How can I filter (or automatically sort) Email?
Author: Joseph Tam
Date: Aug 6, 2004

The utility most people use to filter mail is procmail. You can read up on the usage of procmail by reading these online man pages:

  • man procmail (manual page on the procmail utility)
  • man procmailrc (manual page on the ~/.procmailrc configuration file that governs how mail will be sorted)
  • man procmailex (manual pages with some examples of usage)
The steps are:
  1. Create your ~/.procmailrc file (see man page for procmailrc) and configure how you would like your mail to be sorted.

  2. Forward your mail through procmail via the .forward mechanism. For example,

    "|exec /usr/local/bin/procmail"
  3. Test, test, test.


  1. Using procmail to try to directly filter spam is a tall order. The problem is that spam is hard to characterise in terms of patterns. You may try to do the easy stuff:

    	:0 H
    	*^Subject: .*viagra
    but you'll find that you'll be constantly editing your procmail script since spammers are wiley enough to keep changing "viagra" to "vi@gr@" to defeat such pattern matchers. However, if you have unwanted mail from one source, procmail will handle it just fine.
  2. An improperly written procmail can consign all your mail to oblivion. Test your script carefully, and perhaps turn on logging so you'll have an idea of where the mail is going.