Skip to content | Change text size

ITS home

 

Setting Mail Filters for Unix

NOTE: Spam mail filters for Unix/Linux are unsupported. Please do NOT contact the ITS Service Desk if you are having problems.

If you find there are errors/corrections or have suggestions for these instructions, please email Shane.Hjorth@its.monash.edu.au

Introduction

One of the easiest ways to filter SPAM emails in a Unix/Linux enviroment is to use Procmail. Procmail is available on the Monash Unix servers (e.g. SNG). The following steps have been tested using a staff account on SNG.

Step 1 : Check Procmail

Verify that procmail is installed on the Unix/Linux system that you wish to run the rule on. Try running the command "procmail -v". Locate where procmail is current installed by running the " whereis procmail" command (under solaris you may need to run /usr/ucb/whereis). For example:
bash-2.03$ /usr/ucb/whereis procmail
procmail: /usr/local/bin/procmail
You will need to remember the location of procmail for Step 2.

Step 2 : Enable procmail

Modify the .forward file in the user's directory for whom you wish to enable spam filtering. You will need to replace "jcitizen" with the username of the user for whom spam filtering is to be enabled.

Add the following line to ~/.forward (using the location of procmail as found in Step 1)
"|exec /usr/local/bin/procmail -f- || exit 75 #jcitizen"
NOTE: The quotes in the above ~/.forward file are necessary

Step 3 : Add procmail rule

If you have not previously used procmail, you may wish to add the following lines to the top of the procmail configuration file (~/.procmailrc). The first command creates a procmail debug fil e called "procmaillog" in the users directory.

The second line tells procmail to place a filtered emails in the mail/ folder in a users directory. The email reader program pine uses the mail/ folder. If you use mutt, please set the MAILDI R to $HOME/Mail. (NB: the uppercase "M").
LOGFILE=$HOME/procmaillog
MAILDIR=$HOME/mail

The following rule will filter spam into a folder called, "spam".

The rule should be placed after any other procmail rules you may have that filter mail from mailing lists and other "known" sources.

Add the following to your ~/.procmailrc file

# File as SPAM if score is above 5 stars (default)
:0:
* ^X-Spam-Level: \*\*\*\*\*
spam

Step 4 : Test procmail rule

Visit the following site and send a test 'spam' email with a score of 5 or above to the user's Unix/Linux account. The email should then have been filed to the "spam" folder (using pine, clic k on "Folder List" then select the folder "spam"). If this is not working, check the "procmaillog" file in the home directory to see if there are any errors.

Send Test Spam

NOTE: If your procmail configuration or .forward file is not set correctly you could lose email permanently. Make sure that you test the procmail rules straight after making configuration cha nges.