Procmailrc Auto Reply with out Caching the email
Thursday, February 11th, 2010The other day at work I had to figure out how to accept a email give a reply to anyone that ever sends a email no matter how many times they email the address. Everything I could find had caching in it, with a little digging and poking around the web I found some information that lead me to this solution:
# Auto Reply without caching
# Creator: Richard Genthner
# Date 11-FEB-2010
#
# SENDER the email you want it to look like it came from
# SUBJECT What you want to change the subject to
# FILE the name of the auto reply message
SENDER=bob@example.com
SUBJECT="My Contact information has changed"
FILE=.autoreply_mesg
# Processor this will send the incoming message to /dev/null after sending a auto reply
:0 h c
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-Loop: $SENDER
| (formail -r -A"FROM:$SENDER" -A"X-Loop: $SENDER" -I"Subject:$SUBJECT";\
cat $HOME/$FILE) | $SENDMAIL -t
:0
/dev/null
Lets break this done in to sections. First we have is this:
SENDER=help@example.com
SUBJECT="Our Support information has changed"
FILE=.autoreply_mesg
In this section we are setting the SENDER which is the email address that we want the message to look like. SUBJECT is the Subject we want to replace the RE: blah blah with something that is informational. FILE is the name if the file containing our message. In the next section we have the following bits:
:0 h c
* !^FROM_DAEMON
* !^FROM_MAILER
* !^X-Loop: $SENDER
| (formail -r -A"FROM:$SENDER" -A"X-Loop: $SENDER" -I"Subject:$SUBJECT";\
cat $HOME/$FILE) | $SENDMAIL -t
:0
/dev/null
So at first this looks cryptic but lets break it down line by line. So frist we have the :0 to accept anything then h and c tell procmail to keep a copy of the email just in case we need to process it more then in just this one block. * !^FROM_DAEMON says if its not from a daemon then proceed tot he next step. * !^FROM_MAILER means if not from a auto mailer aka mailing lists then proceed to the next step. * !^X-Loop: this mean is that if not a mail loop then proceed to next step. Which is the formail command. Let break this down by options, first we have -r which mean Generate an auto-reply header. This will normally throw away all the existing fields, then we have -A which allows us to apply custom information to the header fields, -I that any existing similar fields are simply removed. then we are cat’ing the auto reply file in the body of the message and then passing it off to the sendmail to send the file.