Tim writes on 18 April 1997 at 13:46:27
I'm looking for a recipe that will allow me to send change of address
responses to incoming messages (and redirect to the new address).
IE:
mail to user(_at_)combdyn(_dot_)com is forwarded to
user(_at_)cdlsystems(_dot_)com
and a message is sent to the post informing them of this fact.
The following recipe should do what you want. It will match on any email
sent to 'user(_at_)combdyn(_dot_)com' and send an email off with the new
subject of
'My NEW email address', stick the contents of the file 'new-email-address'
Here's a solution I put together a number of years ago; could use some
tweaking, but it might be a good start.
I was thinking this morning that we need to work on an expanded
"procmailex" man page or something. "Recipes for common operations".
Or just point everyone to Alan Stebbens' procmail library. :-)
Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>
http://www.bristol.com/~DanS
Bristol Technology B.V. +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands {info,jobs}(_at_)bristol(_dot_)com
-----
#
# J. Daniel Smith
# 18 April 1993
#
# ~/.procmailrc file to process mail for users that are no longer at
# Applicon.
# * bounce the message back to the sender telling them user is no
# longer here and give forwarding address
# * forward message onto recipient using new address with a comment
# telling them is passed through Applicon
PATH=/bin:/usr/bin:/usr/local/bin
SHELL=/bin/sh
# log everything verbosely, since I want to see how all this works
LOGFILE=/etc/mail/LOG
VERBOSE=on
# cause procmail to exit with exit code 67 = EX_NOUSER; this will make
# sendmail bounce the message
TRAP="exit 67;"
##### THIS MUST BE THE FIRST RECIPE
# Add an X-Forward-To: header to the mail message so that later
# recipies can check the forwarding address.
# Also be sure there is a Subject: line in the message
##### THIS MUST BE THE FIRST RECIPE
:0hf
| formail -i "X-Forward-To: ${FORWARD}" -a "Subject: No subject given!"
# find intereseting header lines
FROM=`formail -xFrom:`
TO=`formail -xTo:`
CC=`formail -xCc:`
SUBJECT=`formail -xSubject:`
DATE=`formail -xDate:`
# get the date in RFC822 format for insertion into some messages;
# the "Resent-Date:" field is copied from the "Date:" field on some systems.
# RFC1123 says "All mail software SHOULD use 4-digit years in dates..."
RESENT_DATE=`date '+%a, %d %h %Y %H:%M:%S %Z'`
# The domain to check against for mail forwarding. This is used to
# prevent mail messages that may contain confidential information from
# being automatically forwarded onto the forwarding address.
#
# If mail originates from within ${DOMAIN} and the forwarding
# address is outside of ${DOMAIN}, then the message WILL NOT be
# forwarded on. Mail originating outside of ${DOMAIN} can be
# forwarded anywhere, and if the forwarding address is also within
# ${DOMAIN}, then all messages can be forwarded on.
DOMAIN=slb.com
# several sub-domains could exist in ${DOMAIN}. This is our
# fully-qualified domain name
FQDN=ann-arbor.applicon.${DOMAIN}
# USER is set on the command line from the sendmail aliases file when
# procmail is invoked. Since messages likely will be sent off-site,
# we want to only use a fully-qualified address.
ADDRESS=${USER}(_at_)${FQDN}
#
# forward the message onto the new address if its OK. Remove the
# X-Forward-To: line we just added above if the message is resent.
# Also, add various Resent-* headers to the forwarded message and
# change the Subject: line so the recipient will know it passed through
# our system.
# mail from outside may be forwarded anywhere
:0hf
* $!^From:${ADDRESS}
* $!^From:.*\.${DOMAIN}
* ^X-Forward-To: .
| formail -i "X-Forwarding-Ok: YES"
# anything may be forwarded within domain, but we already handled mail
# from outside above
:0hf
* $!^From:${ADDRESS}
* $^From:.*\.${DOMAIN}
* $^X-Forward-To:.*\.${DOMAIN}
| formail -i "X-Forwarding-Ok: YES"
:0c
* ^X-Forwarding-Ok: YES$
|formail -I "Subject:$SUBJECT [Forwarded from: $ADDRESS]" \
-i "Resent-To: $FORWARD" \
-i "Resent-From: $ADDRESS" \
-i "Resent-Date: $RESENT_DATE" \
-IX-Forward-To: -IX-Forwarding-Ok: \
| $SENDMAIL -oi $FORWARD
#
# Use the regexp from the previous recipe to set an environment
# variable indicating if messages can be forwarded. This is used below
# to tailer the message sent back to the original sender.
FWD_OK="NO"
:Ac
FWD_OK=|echo "YES"
# "bounce" a message back saying this addressee has moved on.
# Carbon copy the forwarded address and the local postmaster.
# Add a "Precedence: bulk" header line to keep programs like
# vacation(1) from trying to respond to this message.
:0h
* $!^From: ${ADDRESS}
|(formail -r \
-I "Subject: your mail to \"$TO\"" \
-I "From: Postmaster(_at_)${FQDN}" \
-I "Precedence: bulk" \
-A "CC: $FORWARD, Postmaster(_at_)${FQDN}" ;\
echo "Mail can no longer be delivered locally to: $ADDRESS" ;\
echo "" ;\
echo "Your message of: $DATE" ;\
echo "Sent to: $TO" ;\
if [ "$CC" != "" ]; then \
echo "Carbon copies to: $CC" ;\
fi ;\
echo "Regarding: $SUBJECT" ;\
if [ "$FWD_OK" = "YES" ]; then \
echo "Has been forwared onto $FORWARD" ;\
else \
echo "Has been bounced back to the originator." ;\
if [ "$FORWARD" != "" ]; then \
echo "Mail originating within the \"$DOMAIN\" domain can not be" ;\
echo "automatically forwarded outside of Schlumberger." ;\
else \
echo "No forwarding address is available for $ADDRESS" ;\
fi ;\
fi ;\
echo "" ;\
if [ "$FORWARD" != "" ]; then \
echo "Please direct all future correspondence to this addressee's" ;\
echo "new address of: $FORWARD" ;\
echo "" ;\
fi; \
echo "If you maintain a mailing list, please determine if" ;\
echo "$ADDRESS (or some form of \"$USER\") can be" ;\
if [ "$FORWARD" != "" ]; then \
echo "be changed to the new address shown above." ;\
else \
echo "removed from it." ;\
fi ;\
echo ""; echo "" ;\
echo "This message was generated automatically by a \"procmail\" script" ;\
echo "on the machine aamail.$FQDN located at" ;\
echo "Applicon, Inc. in Ann Arbor, MI, USA. Questions regarding this" ;\
echo "message itself should be sent to:" ;\
echo " Postmaster(_at_)$FQDN" ) \
| $SENDMAIL -t
# pitch anything that gets through to here; we don't want it
# ending up in somebody's mailbox
:0
/dev/null