Script to Send an email using mail command

Hello all

I'm trying to write a script to send an email, so I can be nnotified when something is going wrong with my system.

I've tried many options with no luck:

mail -s "You've got mail"  somebody@example.com

echo "Mail Body" | mail -s "Subject" somebody@example.com

I tried also to pass parameter via a script with no luck:

#!/bin/bash
# script to send simple email
# email subject
SUBJECT="SUBJECT"
# Email To ?
EMAIL="s.odeh@masiya.net"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text"
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
echo "done"

Does "mail" command requires any special config on my server to let it work.
I'm running Solaris 10.

Many thanks for help.

This is generic, usually works in most of *nix systems. But MTA must be configured (sendmail, postfix, exim, ...). Smart relay is usually the easiest method.

#!/usr/bin/somesh     bash,ksh,dash,...
[ $# -lt 4 ] && echo "usage:$0 From To Subject msgfile" >&2 && exit 1
From="$1"
To="$2"
Subject="$3"
MsgFile="$4"
cat <<EOF | /usr/lib/sendmail  -i -t
From: $From
To: $To
Subject : $Subject

$(cat $MsgFile)

EOF