procmail
[Top] [All Lists]

Sendmail and Procmail receipe help to send auto reply and forward for all users in the domain

2002-11-25 21:54:51
Hi,
Looking through the various news groups, I could not find any thing on the
net, but eventually managed to do this with procmail
So I  Just wanted to share for those who may need this. I was able to use
procmail receipe as below  with Sendmail  to do the following

For example a.com is the old domain and
b.com in the new domain
Given a hundred's of  users whoes email addresses have
moved from one company to another. ie user(_at_)A(_dot_)com to 
user(_at_)B(_dot_)com(_dot_)
I needed to forward all messages to the new account in the new domain  and
do an auto-reply
to the orignator, with an explaination about the new account:


Here is the start

1) In Sendmail's mailertable use
    a.com        /etc/procmailrc-b.com

2) In /etc/procmailrc-b.com


SHELL=/bin/sh
PATH=/usr/local/bin:/usr/local/sbin:/usr/ucb:/usr/bin
LOGFILE=/var/log/procmailog
FORMAIL=/usr/local/bin/formail
SENDMAIL=/usr/lib/sendmail
VERBOSE=on

# find intereseting header lines
FROM=`formail -xFrom:`
TO=`formail -xTo:`
T1=`echo $TO > /tmp/to.txt`
T2=`sed -e 's/a.com/b.com/g' /tmp/to.txt > /tmp/t1.txt`
FORWARDTO=`cat /tmp/t1.txt`
CC=`formail -xCc:`
SUBJECT=`formail -xSubject:`
DATE=`formail -xDate:`

:0wc:
| ( formail -r ; \
  sh "/etc/mail/autoreply.sh";\
            ) | $SENDMAIL -t -fpostmaster(_at_)b(_dot_)com
:0A
 ! -oi -f $1 $FORWARDTO

3) In /etc/mail/autoreply.sh
    #/usr/bin/sh
OLDID=`cat /tmp/to.txt`
NEWID=`cat /tmp/t1.txt`

echo "Dear E-mail Sender:"
echo "Please be advised that your message for $OLDID"
echo "was forwarded to $NEWID"
echo "The reason for this is that the above-mentioned recipient(s)"
echo "has/have "a.com" in the domain-portion of the address(es)."
echo "The "a.com" domain is obsolete and has been Changed into the"
echo "following domain:"

echo "  b.com      for All Employees"

echo "Please be aware, this a.com address will not"
echo "be supported in the future."
echo "The correct address will contain the b.com domain"
echo "So Please update any distribution lists that contain addresses in the"

echo "obsolete format."

echo "Thank you for your co-operation."
echo Postmaster(_at_)b(_dot_)com


4) chmod a+x /etc/mail/autoreply.txt

Done.

Test by Sending mail to the user(_at_)a(_dot_)com mails will be forwarded to the
corresponding user in b.com to user(_at_)b(_dot_)com and Sender will be 
responded back
with the message above at the same time.

There may be a better way of doing this. If some one has one please send it
to me so that I can Improve on this. But so far All I found on the net was
only one action that would forward all emails to one account or using
.forward files of individual users. Where as this can be used on the
mailhost of any Corporate server that host multiple domains and need to
migrate users from one domain to other at the same time allowing to forward
the old emails to new ones.

Thank you
Rakesh Shah









_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>