website design, maintenance, and hosting

Procmail Filter Tutorial



This document demonstrates how to use procmail to automate mail handling.

General mail handling based on the subject line is discussed first to get you familiar with procmail. Handling multiple mailboxes is discussed at the end of this document.

Assume we get three types of mail:

  1. Information requests (generated by a web form) with the subject line: INFO REQUEST
  2. Orders (generated by a web form) with the subject line: ORDER
  3. Support requests (geneated by a web form) with the subject line: SUPPORT REQUEST

We want all three of these treated differently.

'INFO REQUEST' needs to be saved into a folder called 'Marketing'. This is the most basic type of filtering.

'ORDER'needs to be saved in a folder called 'Sales' and a copy needs to be sent to 'joe' (joe@bigbusiness.com). This shows a little more complex filtering.

'SUPPORT' needs to be saved to a folder called 'Support', a copy mailed to the support team (support@bigbusiness.com) and an acknowledgement sent back to the person who send the mail. This is a custom autoresponder.


Telnet to the server.
Using pico, create '.procmailrc' in your home directory. In the '.procmailrc' file, you are going to put the following text which sets some environment variables:


	PATH=/usr/bin:/usr/local/bin	# Path Variables for the procmail session
	MAILDIR=$HOME/mail		# could be either $HOME/mail or $HOME/Mail
	LOGFILE=$MAILDIR/procmail.log	# Keep a log of what comes in and where it goes
	VERBOSE=no			# No error Reporting --values (no|off yes|on)
	COMSAT=no			# set to no|off
	SENDMAIL=/usr/bin/sendmail	# sendmail location


Adding the following text will match everything with 'INFO REQUEST' in the Subject line and save it to the folder 'Marketing'.
	:0:
	* ^Subject:.INFO REQUEST
	Marketing

Adding the following text will match everything with 'ORDER' in the subject line and save it to the folder Sales' and then send it to joe@bigbusiness.com.
	:0
	* ^Subject:.ORDER
	{
	   :0 c
	   ! joe@bigbusiness.com
	   :0
	   Sales
	}

Adding the text below will match everything with 'SUPPORT' in the Subject line and save it to the folder 'Support', then send it to support@bigbusiness.com and return an acknowlegement to the user who sent the support request.

This is a little more difficult to understand. Make sure that 'SUPPORT' is in the Subject line and that it does not contain data from 'FROM_DAEMON' (listserv's and auto-mailers are suppose to put this in their headers.)

We also don't want to keep replying to other auto responders. This is remedied by putting an 'X' header on your response. (X headers are not seen by standard mail clients) formail reformats the headers of the outgoing message to include 'X-Loop: john_doe@bigbusiness.com' The text that is being displayed is in the file '/home/your_account/acknowledgement.txt' It's mailed to support@bigbusiness.com and saved to the 'Support' folder.

	:0
	* ^Subject:.SUPPORT
	* !^FROM_DAEMON
	* !^X-Loop: john_doe@bigbusiness.com
	{
	  :0 h c
	  | (formail -r -A"X-Loop: john_doe@bigbusines.com " ; \
	  cat /home/your_account/acknowlegement.txt ) | $SENDMAIL -t
	  :0 c
	  !support@bigbusiness.com
	  :0
	  Support
	}

To separate mail by sender (From line) use the following text which will cause any mail from joe@bigbusiness.com to be stored in the folder 'BigBoss'.

	:0:
	* ^From:.joe@bigbusiness.com
	BigBoss

To cause a rule to be applied only to specific mailbox you simply add another line to the rule which requires the To: line to match. Note that in the presence of multiple mailboxes all rules are checked, so this means that a rule that doesn't check who an email is to will be applied to all incomming email.

The following text will cause any mail sent to register@yourvirtualhost.com to be stored in the folder 'Registrations'.

	:0
	* ^To:.*register@yourvirtualhost.com
	Registrations

To modify the autoresponder rule used above to respond to mail sent to support the follow would be used.

        :0
	* ^To:.*support@yourvirtualhost.com
        * !^FROM_DAEMON
        * !^X-Loop: john_doe@bigbusiness.com
	.
	. The rest of the rule goes here.
	.



Have You Seen Me?Call 1-800-THE-LOST if you've seen this child. Click on the image for case details. We support the work of the National Center for Missing and Exploited Children.
Click Here To Add A Missing Child Link To Your Pages!


Back To Web Account Documentation.

 

e-mail

Send E-Mail to:
comments@dss-sites.com

http://www.dss-sites.com

Dealer Support Services
203 Pine Street
Fulton, NY 13069-2429
Phone: (315) 598-8082
Fax: (315) 422-3837