Skip to main content.
Index | Support | Documentation | FAQ

How do I automatically filter E-Mail?

How do I automatically filter E-Mail?

I want to send all my genlist mail to one folder, and all my backup messages to another. I also receive lab results via e-mail can I do anything with them?

There is a utility called 'deliver' that can process incoming e-mail and 'act' on the mail headers e.g To: Subject: etc. This How To gives a brief overview of some of the uses.

(Note: The examples below refer to the the user 'tom' make sure you change all occurrences of 'tom' to the login account you are wanting to filter.)

If you have never used deliver before (most of you won't have),


#----- Cut Here ------

#!/bin/sh
PATH=/usr/local/bin:$PATH ; export PATH ; User=$1
TO=`header -f To -f CC -f Cc -f Apparently-To $HEADER`
SU=`header -f Subject $HEADER`
# OK Look at the Subject and sent it there. e.g. Backup/Pass/Fail
case "$SU" in
*BACKUP*) cat $HEADER $BODY  | deliver -nb Mail/backup ; echo DROP ; exit ;;
esac

# Look at the To header and send it the appropriate mail box
case "$TO" in
*general*)	cat $HEADER $BODY | deliver -nb Mail/general ; echo DROP ;;
*) echo $User ;;
esac

# ----- Cut Here ----

The above options look for 'Subject: BACKUP' and puts all the results into a folder called 'backup' and any messages to 'general' (all genlist mail) will be filtered to the folder 'general'.

Taking it one step further, you receive mail with the subject 'Lab-Results' from one of the labs - yes you can use the same script to automatically add to a record card. As there is no 'standard' for receiving mail (yet) you will have to 'tweak' the script to handle the labs you use.

Add onto the above .deliver script

.. case "$SU" in
.. *BACKUP*) cat $HEADER $BODY  | deliver -nb Mail/backup ; echo DROP ; exit ;;
   *Lab-Results*)  Client=`grep "^Ref No " $BODY |head -1| awk '{ print $4}'`
        /usr/local/bin/vet -p attach $BODY $Client Idexx.$$ ;;	
.. esac

This line will catch any mail addressed to 'Lab-Results', it will look for a line starting 'Ref No' and use the 4th field as the animal number. This will be attached to the card automatically.

(Note: vet -p attach appeared with version 2.191 of Premvet 5).

Yes until there is some standard as to identifying the animal the results refer too there will have to be that cryptic 'grep .... ' part to isolate the animal. Don't worry, if you are wanting to implement this then forward a sample set of results to support and they will send back the cryptic bit.