Unix procmail utility for mail filtering

Procmail is a highly configurable mail filtering utility for Unix mail .
It can automatically put certain email in specified mailboxes/folders.
This guide is intended to assist the user to start using procmail as quickly as possible for mail filtering on CSA/CSD .

Documentation for procmail :
  • “man  procmail” for standard Unix manual.
  • On Linux servers, /usr/share/doc/procmail-3.22/  (may be other version instead of 3.22) –  FAQ, examples etc. that comes with installation.
  • Official procmail site http://www.procmail.org/
  • Search for “procmail manual” in Google. For example, good manual found:  http://userpages.umbc.edu/~ian/procmail.html
Using procmail on CS unix servers:
  1. Create directory .procmail in your home dir: mkdir ~/.procmail
  2. Edit file .procmailrc in your homedir and add the following lines:

LINEBUF=4096
VERBOSE=off
MAILDIR=$HOME/Mail
FORMAIL=/usr/bin/formail
SENDMAIL=/usr/sbin/sendmail
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/log
INCLUDERC=$PMDIR/rc.maillists

Please notice that MAILDIR  is set to the dir where you keep your mailboxes/folders. In this example its set to ~/Mail .Change it to what ever is your dir for mail mailboxes/folders.

 

  1. In file ~/.procmail/rc.maillists you should define the filters that are needed.
    • To filter mail from specific destination that arrives to your Inbox and save it in a file, add the lines (example: From junk@somewhere.co.il save to file $MAILDIR/junk-mail) :

:0:
* ^From:.* junk@somewhere.co.il
junk-mail

  • To filter mail send to specific address (example: To CS-ASSIST-L@TECHUNIX.TECHNION.AC.IL save to file $MAILDIR /assist-list folder:

:0:
* ^To:,* CS-ASSIST-L@TECHUNIX.TECHNION.AC.IL
assist-list

The above recipes have the following format:

:0:
zero or more conditions
one action line

The idea is that if the conditions are met, the action is performed.

Example: Any mail to/from/cc mail group “staff” that arrive to you, will be put in mailbox staff-mailbox

# Put mail from staff mailing list into mailbox staff-mailbox
:0:
* ^(From|Cc|To).*staff
staff-mailbox

You can use Regular Expressions to specify exactly what you want to filter.
More examples can be found in procmail documentation.

  1. To activate procmail on your incoming mail you need to create file ~/.forward in your homedir and add the following line:

“|IFS=’ ‘ && exec /usr/bin/procmail -f- || exit 75 #your-username

Replace your-username with your username, and include the quotes in the line.

Now procmail is activated on each mail arrives to your CSA/CSD account. You can see in ~/.procmail/log  file what happened to each mail that arrives.

To disable procmail, move/delete .forward file.

Please notice that you cannot use vacation utility with procmail activated.

To use vacation, please see  Configuring Vacation Mail With Procmail