Unix Hosting News & Commentary

Procmail

Procmail is an extremely useful utility if you administer or receive mail on a *nix system. Procmail is a (some would argue the) Mail Delivery Agent, or MDA. The purpose of an MDA is to distribute messages to individual mailboxes on a mail server - this is the program that takes the message from the MTA (Mail Transfer Agent, like Sendmail, Postfix, qmail, and others) and places the message in the appropriate mailbox.

The power of procmail comes in when you create custom filters to place messages in certain mailboxes based on the criteria you choose. In procmail terms, these filters are known as “recipes” and are kept in the file .procmailrc in your home directory.

Procmail recipes are first-match - that is, as soon as one of the recipes matches the message being filtered, processing stops. (This can be avoided, as we shall see).

Let’s examine my procmailrc:


First we tell procmail some basic environment information:

Next we set up our first recipe. As you have already seen, comments begin with an octothorpe, and now we see that the recipe itself begins :0:

To decode the above, the recipe says “if the From, To, Cc, or Bcc fields begin with the pattern some character(s) omerset (some more characters) hardcorp then that email should be delivered to the somersethardcorp mailbox.

But we can even get tricky - how about spam filtering via bogofilter?

There are actually 3 recipes in that portion. The first pipes the message out to bogofilter, with the appropriate arguments. The second says that if an error is encountered, output some information. And the last recipe files the message into the spam folder if the (newly-created) X-Bogosity header contains ‘Spam’.

The last recipe says that, if none of the other conditions have been met, we should deliver that message to the inbox folder.

Notice that the way to match all messages is simply to provide no conditions - pretty simple.

Procmail is very powerful, and can do much more than these simple examples. The procmailrc man page contains many more examples.
.procmailrc

  1. No user reviews yet.


Leave a Reply





Blogroll