Using Procmail   «Prev  Next»

Lesson 9 Filtering mail
Objective List techniques for filtering mail.

Question: Which techniques exist for filtering email for maildrop on Red Hat? There are several techniques available for filtering email for maildrop on Red Hat. Here are a few examples:
  1. Using Procmail: Procmail is a popular mail filtering program that can be used with maildrop. With Procmail, you can create filtering rules to process incoming email messages based on criteria such as sender, subject, or content. To use Procmail with maildrop, you would typically set up a .procmailrc file in each user's home directory, which would contain the filtering rules.
  2. Using Sieve: Sieve is another mail filtering language that can be used with maildrop. With Sieve, you can create filtering rules that are processed on the mail server before messages are delivered to the mailbox. Sieve rules can be created using a text editor or a graphical interface, and can be applied on a per-user or system-wide basis.
  3. Using SpamAssassin: SpamAssassin is an open-source spam filter that can be used with maildrop. With SpamAssassin, incoming email messages are analyzed for spam characteristics and assigned a score. Messages that exceed a certain score threshold are then filtered out or marked as spam. To use SpamAssassin with maildrop, you would typically set up a .procmailrc file or a Sieve rule to invoke the SpamAssassin filter.
  4. Using Regular Expressions: Regular expressions can be used with maildrop to filter incoming email messages based on patterns in the message headers or content. For example, you could create a regular expression to filter out messages from a specific sender or containing certain keywords. To use regular expressions with maildrop, you would typically create a filtering rule in the maildroprc configuration file.

These are just a few examples of the techniques that can be used for filtering email for maildrop on Red Hat. The specific technique used may depend on the needs of your email system and the preferences of your users.

Filtering email in procmail

Filtering email requires that you know something about the mail you want to filter. Obviously, if you have received hostile email from someone before, you know his or her email address and can filter it easily. Unfortunately, it's very hard to decide what email to filter before you've received that email. For example, say you want to filter any email advertising credit cards. You might instruct procmail to throw away any email containing the words "credit card." However, if your spouse sends you an email saying the credit card company called for your overdue payment, procmail will blindly filter that legitimate email and you'll never see it. There are three general rules, or laws, to follow regarding filtering email, described in the following filter-email.

The third law, regarding conditions use, warrants a little more explanation. For example, you might create the following condition to send all email from "" into the. Bit bucket: UNIX jargon for /dev/null. It is a device that data can be written into, but never retrieved from. In effect, it's an information trashcan.

* ^From:.*@.* /dev/null

Unfortunately, this recipe also matches all email from "", which happens to be mail you want to receive.
The best way to write this recipe is to explicitly expect mail from either the "" domain or a host inside the "" domain. To do this, use:
* ^From:.*
* ^From:.*@.*\
Check the procmailex man page for a long list of procmail recipe examples and explanations.
The next lesson explains how to test filters.