cse taggi

Log in

Filtering email



How to filter email

Most mail clients nowadays have a filtering system built into them. This can usually be setup fairly easily through the client's graphical interface. This document, however, focuses on the use of procmail to filter email. procmail is a *nix based application that can filter you email before your email client sees it, and is more powerful than most (all?) client-based filters.

Procmail basically has 2 functions - a mail agent and a mail filter. We already have a working mail system, so procmail is available to be used as a mail filter. Procmail comes with 3 binaries - procmail, formail and lockfile - but you only need procmail to get started. The other 2 are used for more complex setups.

To set up a procmail mail filter you need to create a file called .procmailrc in your home directory. This is the file which will contain all of your filtering rules. A simple .procmailrc file that filters out any mail from a unsw.edu.au address into a folder called unswmail, and anything marked as being SPAM (by either ITS's spam filter, or from CSE's own spam filter) into a folder called spam could look like this:

LOGFILE=${HOME}/.procmaillog MAILDIR=${HOME}/mail DEFAULT=${HOME}/.incoming-mail :0: * ^From: .*unsw.edu.au unswmail :0: * (^X-Spam-Flag: YES|^X-CSE-Spam-Flag: YES) spam

Any mail that doesn't match a filter will get put into the ${DEFAULT} file, in this case ${HOME}/.incoming-mail

When you log into a CSE machine, it will automatically detect the presense of a .procmailrc file in your home directory. Note that this will only happen if you do not have a .noautomail file in your homedir. Once the .procmailrc file is detected, it will then set up your $MAILDROP so that promail Just Works.

You will need to log out and back in again for your mail to start being filtered.

Procmail has several manpages. You can look at man procmail for an introduction to the whole shebang; you can look at man procmailrc for all you wanted to know about procmail rules; or you can look at man procmailex for examples of .procmailrc rules, to get started quickly. Also, since procmail is a very popular program, there are loads of web links with instructions on using it to filter all sorts of email, including viruses and spam.

For more information on how to filter out spam, please refer to Filtering out spam.

If you really mess things up with your mail filters, and you think you may have lost some mail, you can recover the emails off our mailserver.

Tags for this page:

email filtering procmail