#!/usr/bin/sh
# Script to send email from Solaris to a user
# This script will handle text in the body, as well as an attachment
# This is really just an API to wrap sendmail nicely
# Patrick O'Reilly - 2000/06/08
# Make sure we have the mandatory arguments
emailTo=$1
emailFrom=$2
emailCC=$3
emailSubject=$4
emailBody=$5
emailAtt=$6
emailAttLbl=$7
# Debug
echo "To:$emailTo 
From:$emailFrom 
CC:$emailCC 
Subject:$emailSubject 
Body:$emailBody 
Att:$emailAtt 
AttLbl:$emailAttLbl " > /tmp/debug.afsendmail.dat
# Display an error message if there are no arguments
if [ "$emailTo" = "" ]
then
    echo "$0 : insufficient number of arguments"
    echo "usage : $0 To [From] [CC] [Subject] [Body] [Attachment] [AttLabel]"
    echo 
    exit 0
fi
# Set the emailDate value
emailDate="Fri 09 Jun 2000 1500 GMT+2"
# Insert a default "From:" email address if none is specified
if [ "$emailFrom" = "" ]
then
    emailFrom="astraadmin\@mip.co.za"
fi 
# Insert a default "Subject:" if none is specified
if [ "$emailSubject" = "" ]
then
    emailSubject="Information From Astra"
fi 
# Insert a name for the attachment if none is specified
if [ "$emailAttLbl" = "" ]
then
    emailAttLbl=$emailAtt
fi 

# Here is where we actually create the email and pipe STDOUT to sendmail
(
#    echo "Date: $emailDate"
    echo "From: $emailFrom"
    echo "To: $emailTo"
    echo "CC: $emailCC"
    echo "Subject: $emailSubject"
    echo
    # If a valid body exists then send it
    if [ -f $emailBody ]
    then
        cat $emailBody
        rm $emailBody
        echo
        echo
    fi
    # If a valid attachment exists then unix2dos and uuencode it, and send it
    if [ -f $emailAtt ]
    then
        unix2dos $emailAtt $emailAtt.unix2dos
        uuencode $emailAtt.unix2dos $emailAttLbl
        rm $emailAtt.unix2dos
    fi
) | /usr/lib/sendmail $emailTo $emailCC
# That's all folks!
