-->
🏠 🔍
SHAREOLITE

Beginners Linux shell script to send a Email using sendmail

Below mentioned is a beginners Linux shell script to send Email using Linux sendmail command. 

Copy the code below highlighted in blue , save it in a file and execute for output. There are variables FROM,TO,SUBJECT,TEXT which be configured based on your requirement.

#!/bin/sh
# This gives an example of sending an HTML message.
#

FROM="james.eric@shareolite.com"
TO="anna@shareolite.com"
SUBJECT="Happy Birthday Anna"
TEXT="Hi Anna, Wish you a Happy Birthday and all the very best wishes"

(
echo "From: $FROM"
echo "To: $TO"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed;"
echo ' boundary="BOUNDARY"'
echo "Subject: $SUBJECT"
echo ""
echo "This is a MIME-encapsulated message"
echo "--BOUNDARY"
echo "Content-Type: text/plain"
echo ""
echo "This is what someone would see without an HTML capable mail client."
echo ""
echo "--BOUNDARY"
echo "Content-Type: text/html"
echo ""
echo "<html>
<blockquote><font color='green'>GREEN</font> <font color='white'>WHITE</font> <font color='red'>RED</font></blockquote>
$TEXT
</body>
</html>"
echo "--BOUNDARY"
) | /usr/sbin/sendmail -t -v -f "$FROM"

Hope this is useful to some Linux beginners

Comments

–>