Procmail is a mail delivery agent ( MDA), which is used for server-side filtering of e- mail messages.

Normally procmail is called from a Mail Transfer Agent ( MTA) such as sendmail or postfix. Pre-sorting of incoming e -mail messages can then be implemented into folders by Procmail. In this case, e- mails can be filtered based on various characteristics, such as:

  • Return address
  • Receiver
  • Subject line
  • Belonging to a mailing list
  • Content of the e -mail
  • Spam ( in association with spam detection programs such as SpamAssassin )

To this end, procmail uses, among other regular expressions. Procmail also has the ability to call external programs or automated to respond to e- mails; as can be popular features such as forwarding, autoresponder or vacation implement circuits.

To emails to filter into existing mailboxes, Procmail provides the utility with formail.


The following sample Procmail control file (usually. Procmailrc ) scans incoming mails with Spam Assassin and then filters them.

SHELL = / bin / bash MAILDIR = $ HOME / mail DEFAULT = $ MAILDIR / inbox Lockfile = $ HOME / .lockmail: 0fw | / Usr / bin / spamassassin: 0H * ^ X-Spam- Level: \ * \ * \ * \ * \ * \ * \ * \ * \ * \ * / dev / null: 0H: * ^ X-Spam -Status: Yes. / Spam # Anything that Has not been delivered by now will go to $ DEFAULT # Using a lockfile = $ DEFAULT $ LOCKEXT: 0 initiates a filter rule. The attached fw the first rule ensures that procmail will wait until the program is completed. The attached H of the following two rules ensures that only the header of the e -mail to be searched. A final colon tells procmail to use file locking. This is always necessary when it is not ensured that the rule can be executed multiple times in parallel. For example, if a mail should be sorted in a particular mbox file, which by simultaneous accesses a data loss would occur.

Explanation: First, the e -mail is sent spamassassin from a pipe to the program and wait until the program is completed. The scanned mail now goes through the next filter rules. SpamAssassin adds sighted emails, add the header X -Spam-Status, which ( for detected spam ) or No ( for unrecognized as spam ) is depending on the selected threshold Yes. In addition, SpamAssassin adds a header that consists of * characters. The number of characters stands for the rounded score ( ie probability that the message is spam ) e -mail. The score, after which a message is identified as spam is, by default when fifth

The example filters on the number of characters. Find Procmail ten or more * characters, so the email is stored in the zero device and thus discarded. When a message is generally identified as spam, the message in the spam folder is stored. All other e- mails are delivered in the normal inbox.