| ACADEMIC COMPUTING and COMMUNICATIONS CENTER | |||||||||
| |||||||||||||||||
procmail -- File Clerk for the Heavy-Duty UNIX Email User | |||||||||||||||||
Note added March, 1996: The way you turn procmail on and off has changed since this article was written. You used to specifically turn it on and off by putting or removing a line in a .forward file in your home directory. Now, just the existence of the procmail .procmailrc file in your home directory turns procmail on, and the easiest way to turn it off is to rename the .procmail file. This online version of the ADN Connection article has been updated to reflect this change. Note added Way Late in August, 2005: Poor UNIX Guru. He's not earning his pizza on procmail any more. The ACCC's Web Email filter tool has taken all the guesswork out of procmail filters. Stop by the ACCC's Email home page for more information. Click the purple Email link above.
Warning: If you find this article confusing, and if the procmail man pages don't make things clearer, drop in on your local UNIX guru. (Hint: most UNIX gurus like pizza!)
|
|||||||||||||||||
| Do you get a lot of email? | |||||||||||||||||
|
I do. It sure would be nice to have a secretary who would organize my mail into notebooks for me. Perhaps mail from LISTSERV lists would go into one notebook, urgent mail into another, mail from special friends into a third, and log reports into a fourth. And perhaps he'd even forward certain notes to colleagues who might be interested, or let my correspondents know when I'm on vacation (but only one reminder per correspondent, even if I get five messages from them). And, of course, he should do all this within seconds of my receiving the incoming mail. Well, I don't have a secretary. But I do have procmail. Procmail is an automatic mail processing program, developed by Stephen van den Berg in Aachen, Germany and currently running on tigger and icarus. If you only get five to ten notes a day, you may as well stop reading this now, because for you using procmail would be like using a jackhammer to crack an egg. But if you have to wade through 50 or 100 or even 200 notes on a wide variety of subjects each day, procmail can turn those eggs into omelettes for you. You can use procmail just to forward mail, but it also lets you sort your notes into multiple inboxes. This feature works well with pine's folder structure. By the way, Eudora (the personal computer electronic mail software in the MS-Windows and Apple Macintosh versions of the ADN Network Services Kit) also has several of these mail sorting features built-in. The electronic mail systems on CMS, however, do not. So if you're really into electronic mail and you currently use the electronic mail systems on CMS to read, send, and manage your electronic mail, consider moving your electronic mail base of operations to UNIX or to your office personal computer, where it is more convenient to sort your mail automatically. |
|||||||||||||||||
| How Procmail Works | |||||||||||||||||
|
After you turn procmail on -- by creating a .procmailrc file and
putting it in your home directory -- procmail will process each note you
receive, when you receive it, according to the group of "recipes" you devise
for it. Those recipes go into your .procmailrc file. A sample .procmailrc
file is given in the box below.
## ## Copy all incoming mail to the backup directory, just in case ## Note: you must already have a directory named backup :0 c backup ## Prune the backup directory; keep only the 32 most recent notes :0 ic | cd backup && rm -f dummy `ls -t msg.* | sed -e 1,32d` ## forward a copy of all notes about procmail to adabyron@uic.edu :0 c * ^Subject:.*procmail ! adabyron@uic.edu ## Place all notes from ACADEMY in a separate pine folder :0: * ^Sender:.*ACADEMY mail/academy ## Autoreply to notes from creditors :0 * ^From:.*irs.gov | (formail -rk -I "From: <moneybags@tax.cheat.com> \ echo "The check is in the email") | $SENDMAIL -t Each procmail recipe consists of one or more conditions, like "Is this note from John?" or "Is this note about electronic mail?", followed by an action like "file it in my john.inbox" or "forward it to Bob". When an incoming note matches a condition, the corresponding action is taken. The conditions can use regular expressions, and the actions can be arbitrary programs, so this is a very flexible system. Of course, the actual recipes can be a bit more cryptic than these examples, and you'll have to read a few man pages and experiment a bit before you'll get yours to work. But always start with the first two recipes in the box; they save backups of your mail, so you won't lose mail while you're figuring out the details. And always test new procmail rules; don't just assume that they will work. |
|||||||||||||||||
| Running Procmail | |||||||||||||||||
| To turn procmail on, create a file named .procmailrc in your home directory, containing your procmail conditions and instructions. Make sure your ~/.procmailrc file is world-readable but not world-writable. | |||||||||||||||||
| You'll Need More Information Before You Use Procmail; Here's Where to Get It | |||||||||||||||||
|
There are several man pages associated with procmail. I suggest starting
with man
procmailex, which provides some fairly straightforward examples of
what can be done. man
procmailrc gives the exact syntax of the instructions you put in your
.procmailrc file. You should also look at man
formail for information on procmail's ability to manipulate mail headers.
For example, we use procmail, formail, and some custom filters to deal
with incoming requests for massmail use.
Go ahead and experiment, but don't leave procmail turned on for any length of time until you are sure it is working properly. Turn it off by renaming it to, say, procmail (without the "dot"). It's quite easy to lose mail if your .procmailrc file is messed up -- that's why I have the first two recipes in the sample .procmailrc file in my .procmailrc file. That way I have backup copies of my mail just in case. Now if only I could write a procmail recipe to give sensible answers to all my procmail questions, I'd really be ahead of the game! Comments are appreciated; send them |
|||||||||||||||||
| The ADN Connection, Sept/Oct 1995 | Previous: The ADN Post | Next: Free Seminars for Fall 1995 |
| 2005-8-23 connect@uic.edu |
|