####[ How-Do-I Documents ]######################################

Sub : Setting a mail autoresponder using procmail

How-Do-I set up a mail autoresponder using procmail alone 
for things like vacation notices ?

################################################################


1        Introduction

1.1      There are times when there is a  need  to set up auto-
         responses for mails (e.g. during vacations) ... If you
         are using fetchmail, procmail, sendmail combination to
         do your mailing, a quick-and-easy autoresponder can be
         set up using procmail alone.
         
1.2      There is no need for installing external programs like
         vacation for this purpose.
         
2        General Priciple

2.1      Procmail itself is endowed with features to respond to
         incoming mails automatically. The .procmailrc needs to
         be tailored for this purpose.
         
3.       Steps

3.1      Make a file as below which needs to be  pre-pended  to
         your existing .procmailrc. This assumes that your mail
         id is myself@some.isp.net, and assumes that your send-
         mail is  installed at  /usr/sbin/sendmail.  Similarly,
         it assumes your mail  directory to be  $HOME/Mail. You
         need to put appropriate substitutions for your system.
         
         -------------------------------------

         VERBOSE=off
         LOGFILE=$HOME/procmail.log
         MAILDIR=$HOME/Mail
         SENDMAIL=/usr/sbin/sendmail

         #########################################
         # Auto-responder for vacations. Please
         # insert text in $MAILDIR/message.txt
         #########################################

         :0 ic
         * ^TOmyself@some.isp.net
         *!^FROM_DAEMON
         *!^X-Loop: myself@some.isp.net
         |(formail -r -A "Precedence: Auto" \
         - -I"From: My_Name " \
         - -I"Subject: Automated acknowledgement" \
         - -A "X-Loop: myself@some.isp.net"; \
         cat message.txt )| $SENDMAIL -t 

         ------------------------------------ 
         
3.2      The message that you want to  send  should be in plain
         text, in a file named message.txt  saved in  your mail
         directory ($HOME/Mail), not your home dir.
         
3.3      Your normal .procmailrc  may  be distributing mails on
         the basis of various header fields into different mail
         box files/ dirs. If you want the same  distribution to
         continue, this autorespond snippet  should be inserted
         at the  top  of the  existing .procmailrc, so that the
         autoresponse is executed prior to distribution  of all
         mails to individual files/ folders.               
                 
3.4      Alternatively, you may just replace the .procmailrc in
         use with this snippet. In which case,  all  your vaca-
         tion mail will go into your default mailbox/ maildir.
         
         $mv .procmailrc procmail.orig
         $cp vacation.notice .procmailrc ... 
          (this is assuming that the snippet has  been saved as 
          vacation.notice)
          
3.5      To restore normalcy just copy your original setup back

         $cp procmail.orig .procmalrc
         
         
4        Silly problem

4.1      One of the silliest errors is to forget  resetting the
         vacation notice to normalcy after return. It is better
         to have some system of reminder that  vacation  notice
         is on. I use the following script, which  activates at
         login, run through my .bash_profile/ .bashrc

         ------------------------------------------------         

         #!/bin/sh
         ##############################################
         # Boot up warning in case auto-responder has
         # been set. To be run from  .bash_profile or
         # .bashrc. 
         ##############################################

         if [ -s .procmailrc ]; then
            cat .procmailrc | grep "cat message.txt" > /tmp/auto.chk
            if [ -s /tmp/auto.chk ]; then
               echo 
               echo "NOTICE : Mail autoresponder on vacation notice"
            fi
            rm -f /tmp/auto.chk
         fi

         -----------------------------------------------
                 
4.2      Note, that  what  we are  searching for is the name of
         the message file. If it is not "message.txt", you need
         to change this line at grep ...
         
4.3      Save this script as .autoresponder.chk, and do a chmod
         +x on it to make it executable. At the end of .bashrc/
         .bash_profile add one line:
         
         /home/$USER/.autoresponder.chk
         
         Change $USER to your User Name above.
      
     
5        Execution

5.1      There is nothing further to be done. The next time you
         (or somebody on your behalf) downloads  mail  on  your 
         behalf from the server, this  automated  response will
         be fired off ...
                   
5.2      You are advised to download the  tarball  linked below
         to have a text, html and sgml version of this document
         In addition, it also contains a  bash  script which is
         meant to generate the procmail recipe  for you without
         much typing.  [Download tarball] 
         
         
################################################################

6        Kudos and Brickbats

6.1      This document is released under GNU/ GPL licence. You are
         free to use and distribute this without any encumberances

6.2      Any kudos and brickbats should be directed at:

         USM Bish 

         23 Nov 2001