Responding to Email with procmail


Responding to Email with procmail

procmail can help you automaticallyor selectivelyrespond to email. As you'll see, procmail is very similar to forwarding email and using the vacation program, but you'll probably find procmail much more flexible.

To specify how messages should be filtered (to "write a recipe"):

1.

vi ~/.procmailrc

In vi, access your .procmailrc file.

2.

Move to the end of the file, below the setup information.

3.

:0:

Start a new recipe with :0:, as shown in Figure 11.18. (Don't ask why to use :0:. That's just the way it is.)

Figure 11.18. Add the recipes of your choice to your .procmailrc file.


4.

* ^TOGolfBuddies

Set the criteria for procmail to filter with. Here,

  • * ^TO tells procmail to examine the TO line (and, actually, the CC line, too) of all incoming messages.

  • GolfBuddies is the text to match in the TO line (as in TO: GolfBuddies@ nowhere.nowhen.com). Of course, you'd put in the actual name of the list to look for (or the alias for your mailing list, or whatever), rather than GolfBuddies.

5.

$MAILDIR/FriGolfBuddies

Specify where the filtered mail should go. In this case, filtered mail would go in the FriGolfBuddies folder, but you might filter messages from mailing lists into a listmail folder.

6.

Save and close the file.

To Forward Mail with procmail:

1.

pico ~/.procmailrc

To begin, access your editor and edit the .procmailrc file that you previously created in your home directory.

2.

:0:

On a new line at the bottom of the file, add :0:, which starts a procmail recipe. This basically tells procmail to "lock" your mail directory while it's processing mail.

3.

! myotheremail@example.com

Provide an exclamation point (!)and the address to which to send the mail.

4.

Save and close the file.

Now all email that you receive will be automatically forwarded to myother-email@ example.com.

Use procmail to Toss Spam Messages

The following recipe,

:0: * !^TO.*awr@.*raycomm.com $MAILDIR/spam 


uses a regular expression to filter messages that aren't explicitly addressed to a userid with awr before the @ and raycomm. com at the end and places them into a special folder called spam. Put the spam filter at the end of your list of rules so all of the messages originating from your mailing lists and other important messages are filed first. After testing this and making sure that you like it and it doesn't pitch valuable messages, you could change the last line to /dev/null to just throw away the garbage.

For more complex and sophisticated spam solutions, check the options with a Google search for procmail spam filter at http://www.google.com/.


To invoke vacation with procmail:

1.

pico ~/.procmailrc

To begin, access your editor and edit the .procmailrc file that you previously created in your home directory.

2.

:0 c | /usr/bin/vacation jdoe

On a new line at the bottom of the file, add the recipe shown to send a copy (the c at the end of the first line) of your email to the vacation program. See Announcing an Absence with vacation in this chapter for more information about the vacation program.

3.

Save and close the file.

Now all email that you receive will be stored and passed along for the vacation program to respond to.

Tips

  • Your .procmailrc file gets processed in order. As soon as a recipe matches an incoming email message, it's applied. So if your first recipe is the forwarding recipe above, procmail will never even get to any later recipes. If no recipes are matched, mail will be delivered to the DEFAULT location you specified (see Configuring procmail, earlier).

  • After you set up your procmail processing, be patient. Sometimes procmail processes email on a specific schedule (hourly, for example), so testing it may be a little time-consuming.


Sample procmail Recipes

The following recipes, with annotations, should help you get started filtering with procmail.

# Filter based on the To:, Cc: and  similar headers :0: * ^TO.*awr@.*raycomm.com $MAILDIR/interesting # Filter based on the subject :0: * ^Subject:.*Status Report.* $MAILDIR/status-reports # Filter based on sender :0: *^From:.*spammer@example.com $MAILDIR/IN.TO-DELETE # Filter directly to garbage,  irrevocably, based on sender :0: *^From:.*spammer@example.com /dev/null # Filter based on size (greater than  1000 bytes) :0: * > 1000 $MAILDIR/longish 






Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net