#!/bin/sh
# Send an email using a different SMTP server when there are more then 50 messages in the incoming milter

len=`ls /var/spool/MailScanner/milterin/ | wc -w`

if [ $len -gt 50 ]; then

        SUBJECT="WARNING: There are $((len)) messages in the Milter!"
        # Email To ?
        EMAIL="foo@bar.net"

        # Email text/message
        EMAILMESSAGE="/root/emailmessage.txt"
        echo "WARNING: There are $((len)) messages in the mail Milter" > $EMAILMESSAGE

        # send an email using /usr/bin/nail
        /usr/bin/nail -r replyto@address.net -s "$SUBJECT" -S smtp=smtp.adifferentserver.net -- "$EMAIL" < $EMAILMESSAGE
fi