#!/bin/bash

MAIL=/usr/sbin/sendmail
MESSAGE_FILE=/tmp/smartd-email-message.tmp
FROM="smartctl@filserver.jocke.no"
TO="$SMARTD_ADDRESS"
SUBJECT="$SMARTD_SUBJECT"

echo "To: $TO" > $MESSAGE_FILE
echo "From: $FROM" >> $MESSAGE_FILE
echo "Subject: $SUBJECT" >> $MESSAGE_FILE
echo "" >> $MESSAGE_FILE
echo "Device: $SMARTD_DEVICE" >> $MESSAGE_FILE
echo "Device-type: $SMARTD_DEVICETYPE" >> $MESSAGE_FILE
echo "First occurence: $SMARTD_TFIRST" >> $MESSAGE_FILE
echo "" >> $MESSAGE_FILE
echo "" >> $MESSAGE_FILE
echo "$SMARTD_FULLMESSAGE" >> $MESSAGE_FILE
echo "" >> $MESSAGE_FILE

$MAIL -t < $MESSAGE_FILE

rm $MESSAGE_FILE 2> /dev/null

exit 0