Forwarding E-mail & Filtering Spam with Procmail

Forwarding E-mail & Filtering Spam with Procmail

In order to provide flexibility in the processing of e-mail, the CS departmental e-mail system employs Procmail to allow users to configure their own filtering and forwarding. New accounts are set up with a default configuration that implements spam filtering and is easy to modify.

Users who forward their e-mail to Gmail or other off-site accounts are strongly encouraged to filter out spam prior to forwarding. Failure to do so will cause the departmental mail server to be added to spam databases, which can cause your forwarded messages to be delayed or even rejected. This situation can affect not only individual users, but all users who forward their e-mail from the departmental server to a given site.

Procmail configuration files:

Each time an e-mail message is received for your account, Procmail is automatically invoked, and it looks for a .procmailrc file in your home directory. This file contains configuration recipes which tell Procmail what to do. There are often other, related files (such as .procmailrc.spam) that can also become part of the configuration via INCLUDE or SWITCHRC directives. Search for “SPAM” or “spam” in your .procmailrc file, if you are unsure of how your spam filtering is set up. Sample Procmail configuration files can be found in the /usr/project/support/dotfiles/ directory. (Since they start with a “.”, use ls -a in order to list them.) These are the same files that are copied into new accounts; many comments are included to explain what the recipes are doing and how you can modify them. If you do not have a .procmailrc file, or you need spam filtering added, you may copy these, or ask the CS Lab Staff for assistance.

Filtering spam:

Please see CS Default Spam Filtering for User Accounts for a discussion of the spam filtering with Procmail and the default configuration. A more general discussion of spam filtering options can be found at Spam Filtering in the CS Department.

Forwarding e-mail:

Users who forward their e-mail to Google Gmail, Yahoo! Mail, or other off-site accounts or addresses are strongly encouraged to filter out spam prior to forwarding, for the reasons described above.

An example of how to do this is included in the default CS setup files in /usr/project/support/dotfiles/. See the files: .procmailrc and In the first one, search down for “GMAIL”. This special case includes code to prevent mail loops in the case that e-mail is forwarded in each direction (something you should probably avoid doing). Addresses other than Gmail addresses could be used here as well.

Assuming that spam filtering has aleardy taken place above in the .procmailrc file, simple forwarding is also an option. Scan down for “FINAL FORWARDING” for an explanation.

How not to forward e-mail:

A common method of forwarding e-mail is through the use of a ~/.forward file. For the reasons mentioned above, the CS Lab Staff strongly discourage this method. Please use Procmail, and feel free to ask for assisstance.


For more information, please see:

Unix man (manual) pages (command line or web lookup):
Try lookups on: procmail, procmailrc, procmailex, procmailsc
Procmail on Wikipedia:
Procmail official website:
See “Interesting and Useful Links” for links to some tutorials.
CS Default Spam Filtering for User Accounts
Spam Filtering in the CS Department

If you have any questions or need help, please contact the Lab Staff.