Monday, October 24, 2011

Send mail bash script

Sample Shell Script Here are two samples of shell script to send an email:
1.

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


2.

#!/bin/sh
while true
do

subject="your-email-bsubject"
mailaddr="admin@example.com"
message=`you-email-body`
encsubject=`echo $subject`

cat << EEE | mail -s "$encsubject" $mailaddr
$encsubject
$message
EEE
exit 0
done

No comments:

Post a Comment