ProcmailRC recipes

Standard

Sending an auto reply while on vacation

PATH=/bin:/usr/bin:/software/common/bin
MAILDIR=$HOME/mailroom #you’d better make sure it exists
LOGFILE=$MAILDIR/procmail.log #recommended

# Vacation work-alike (3/6/98) Accurso
#
# This is an annotated and slightly modified version of the
# vacation work-alike example given in “man procmailex”.
# The use of ^TO is the significant modification.
# See also “man procmailrc”.
#
# First we must decide whether to send an auto reply.
# All the egrep conditions (* lines) must be satisfied.
# If so, headers (h) of the current message are fed to
# formail which checks the vacation.cache to find out
# if the sender has already received an auto reply.
# We will lock vacation.lock while processing this
# recipe to avoid clashes when updating the cache.
#
# This recipe waits (W) for a return from formail.
# Without the (c) procmail would stop processing
# after completing this recipe because it is
# a delivery recipe, it delivers headers to formail.
#
# The conditions ^TO and ^FROM_DAEMON are more than
# meet the eye.
#
# ^TOzz1demo is satisfied if zz1demo
# appears in any recipient header To: Cc: Bc:.
# This avoids sending auto replies to messages that
# were addressed to an alias or maillist, but not
# explicitly to zz1demo.
#
# !^FROM_DAEMON makes sure we do not auto reply to
# messages from any of a wide variety of daemons.
#
# “!^X-Loop: zz1demo@ieng9.ucsd.edu” avoids replying
# to our own auto reply, notice below that this X-Loop
# header is inserted into the auto replies we send out.

SHELL=/bin/sh # for other shells, this might need adjustment

:0 Whc: vacation.lock
* ^TOzz1demo
* !^FROM_DAEMON
* !^X-Loop: zz1demo@ieng9.ucsd.edu
| formail -rD 8192 vacation.cache

# Due to (e) recipe below is executed if the preceding one
# returns an error status. In this case it is not really
# and error, it is just the signal from formail to go
# ahead with the auto reply. Notice that if in the
# preceding recipe the egrep conditions are not met
# and that causes the formail cache check to be
# skipped, procmail is [somehow] clever enough to skip
# this recipe.
#
# The headers (h) of the current message are fed to the
# formail in this recipe in order to construct the
# headers for the auto reply.
#
# The (c) in this recipe causes the whole
# current message to be processed after this recipe.
# Typically that means it will be processed with no
# further recipies and that is how you get a copy in your
# mailbox. There is no need for a lock while executing
# this recipe so none is used.

:0 ehc # if the name was not in the cache
| (formail -rA”Precedence: junk” \
-A”X-Loop: zz1demo@ieng9.ucsd.edu” ; \
echo “I received your mail, but I will be away”; \
echo “from the office until Monday Dec 15th.”; \
echo ” “;\
echo “If this is an urgent matter, please call my office XXX-XXXX “;\
echo ” “;\
cat $HOME/.sig \
) | $SENDMAIL -oi -t

Automatically discarding or returning unwanted mail
Return to sender with “reject” notice (not for spam!)

# This procmailrc will automatically reject and bounce mail from
# certain addresses. NOTE: DO NOT USE THIS FOR SPAM! Only use it for
# folks that you know have a valid return address.
#
# This file can be dropped into your home directory as ‘.procmailrc’, or
# inserted into your existing ‘.procmailrc’, with or without the
# comments.
# -zz1sn 2/18/98

#
# The :0 is the start of a rule. Note, blank lines in a rule are NOT
# happy. Don’t insert any blank lines between the :0 and the line with
# $SENDMAIL, or the rule won’t work. Also, don’t put any comments
# within the rule, either.

#
# The *^From:.*example.*nuisance
# line indicates the string you want to match. If the From
# header in the e-mails you want to match looks something like
# From: Block Head <llarry@ancientgames.com>
# you can use a rule like: *^From:.*llarry.*ancientgames
# or perhaps something like *^From:.*Block Head
# (Remember, case is important – capitals are different from lowercase!)
#
# You want to be as specific as possible, but general enough to
# catch the person’s e-mails. The ‘*^From: bit ensures that the
# rule only matches on the ‘From:’ header, and the ‘.*’ sequence
# is a wildcard (match 0 or more occurrences of any character).
#
# Replace ‘example.*nuisance’ with your expression; otherwise, this
# rule won’t do a thing.
#
# If you want to reject mail from more than one source you can
# repeat the whole rule (from the :0 line to the SENDMAIL line)
# as many times as necessary in your .procmailrc file. Put
# a blank line between rules.
#
# This rule bounces the mail. First, it pipes through a series of
# commands that generate a new e-mail. ‘formail’ takes the old e-mail
# and generates a response; we replace the ‘From:’ line with
# ‘devnull@ucsd.edu’ (which silently discards all mail) to prevent
# mail loops caused by ricocheting bounces.
#
# We then pipe the result through $SENDMAIL -oi -t, which tells
# sendmail to ignore dots as end-of-file markers, and to grab the
# sender/recipient info from the message body.
#
# Note syntax; anything that should be in the message needs to go in
# an ‘echo’ statement inside the parentheses. It should be
# double-quoted, and should not contain funny characters (*, $, etc.).
# The ‘ \’ (space-backslash) needs to be at the end of each line
# except the last to indicate that technically the entire rule belongs
# on one line.
#
:0
*^From:.*example.*nuisance
|( formail -rI”From: Responses will be automatically discarded <devnull@ucsd.edu>”; \
echo “Your mail has been administratively rejected.”; \
echo “It was NOT received.” \
) | $SENDMAIL -oi -t

Discard/block e-mail messages (without return to sender)

# This procmailrc will automatically reject and discard mail from
# certain addresses.
#
# This file can be dropped into your home directory as ‘.procmailrc’, or
# inserted into your existing ‘.procmailrc’, with or without the
# comments.
# -zz1sn 3/09/98

#
# The :0 is the start of a rule. Note, blank lines in a rule are NOT
# happy. Don’t insert any blank lines between the :0 and the line with
# $SENDMAIL, or the rule won’t work. Also, don’t put any comments
# within the rule, either.

#
# The *^From:.*example.*nuisance
# line indicates the string you want to match. If the From
# header in the e-mails you want to match looks something like
# From: Block Head <llarry@ancientgames.com>

# you can use a rule like: *^From:.*llarry.*ancientgames
# or perhaps something like *^From:.*Block Head
# (Remember, case is important – capitals are different from lowercase!)
#
# You want to be as specific as possible, but general enough to
# catch the person’s e-mails. The ‘*^From: bit ensures that the
# rule only matches on the ‘From:’ header, and the ‘.*’ sequence
# is a wildcard (match 0 or more occurrences of any character).
#
# Replace ‘example.*nuisance’ with your expression; otherwise, this
# rule won’t do a thing.
#
# This rule silently discards all mail containing the matched From:
# address. If you want to discard mail from more than one address,
# duplicate the entire 3-line rule, from :0 to /dev/null (changing the
# wildcard expression appropriately)
#
#
:0
*^From:.*example.*nuisance
/dev/null