In This article we will see how to send an email notification with HTML formatting. We will see how to create and send following table type structure in an email body.
#----------------------------------------START OF THE SCRIPT--------------------------------------
$ cat Email_In_Html_Format.sh
#!/usr/bin/sh
V_MAIL_TO="Director@kw.com"
V_EMAIL_BODY="Email_Body.html"
#--Below code will be used to generate the HTML code
echo "<html>" > ${V_EMAIL_BODY}
echo "<head></head>" >> ${V_EMAIL_BODY}
echo "<body>" >> ${V_EMAIL_BODY}
echo "<STYLE TYPE="text/css">" >> ${V_EMAIL_BODY}
echo "<!--" >> ${V_EMAIL_BODY}
echo "TD{font-family: Arial; font-size: 9pt;}" >> ${V_EMAIL_BODY}
echo "--->" >> ${V_EMAIL_BODY}
echo "</STYLE>" >> ${V_EMAIL_BODY}
#--Below echo is used to create a HTML table
echo "<TABLE border="2" frame="border" rules="all">" >> ${V_EMAIL_BODY}
#--Below echo is used to create table header.
echo "<tr><th bgcolor=#BDBDBD><font size="2">EMP_ID</font></th>
<th bgcolor=#BDBDBD><font size="2">EMP_NAME</font></th>
<th bgcolor=#BDBDBD><font size="2">EMAP_DEPT</font></th>
<th bgcolor=#BDBDBD><font size="2">EMP_SAL</font></th></tr>" >> ${V_EMAIL_BODY}
#--Below echo is used to generate the data in tabular format.
echo "<tr><td>1001</td><td>A1</td><td>HR</td><td>50000</td></tr> <tr><td>1002</td><td>A2</td><td>MAN</td><td>60000</td></tr>
<tr><td>1003</td><td>A3</td><td>VP</td><td>100000</td></tr> <tr><td>1003</td><td>A3</td><td>CEO</td><td>150000</td></tr>"
>> ${V_EMAIL_BODY}
echo "</table>" >> ${V_EMAIL_BODY}
echo "</body>" >> ${V_EMAIL_BODY}
echo "</html>" >> ${V_EMAIL_BODY}
#--Below code will be used to send email notification
export V_CONTENT="${V_EMAIL_BODY}"
(
echo "Subject: Employees Report"
echo "To: ${V_MAIL_TO}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
echo ${V_CONTENT}
) | /usr/sbin/sendmail ${V_MAIL_TO}
Keep Reading, Keep Learning, Keep Sharing..!!!
$ cat Email_In_Html_Format.sh
#!/usr/bin/sh
V_MAIL_TO="Director@kw.com"
V_EMAIL_BODY="Email_Body.html"
#--Below code will be used to generate the HTML code
echo "<html>" > ${V_EMAIL_BODY}
echo "<head></head>" >> ${V_EMAIL_BODY}
echo "<body>" >> ${V_EMAIL_BODY}
echo "<STYLE TYPE="text/css">" >> ${V_EMAIL_BODY}
echo "<!--" >> ${V_EMAIL_BODY}
echo "TD{font-family: Arial; font-size: 9pt;}" >> ${V_EMAIL_BODY}
echo "--->" >> ${V_EMAIL_BODY}
echo "</STYLE>" >> ${V_EMAIL_BODY}
#--Below echo is used to create a HTML table
echo "<TABLE border="2" frame="border" rules="all">" >> ${V_EMAIL_BODY}
#--Below echo is used to create table header.
echo "<tr><th bgcolor=#BDBDBD><font size="2">EMP_ID</font></th>
<th bgcolor=#BDBDBD><font size="2">EMP_NAME</font></th>
<th bgcolor=#BDBDBD><font size="2">EMAP_DEPT</font></th>
<th bgcolor=#BDBDBD><font size="2">EMP_SAL</font></th></tr>" >> ${V_EMAIL_BODY}
#--Below echo is used to generate the data in tabular format.
echo "<tr><td>1001</td><td>A1</td><td>HR</td><td>50000</td></tr> <tr><td>1002</td><td>A2</td><td>MAN</td><td>60000</td></tr>
<tr><td>1003</td><td>A3</td><td>VP</td><td>100000</td></tr> <tr><td>1003</td><td>A3</td><td>CEO</td><td>150000</td></tr>"
>> ${V_EMAIL_BODY}
echo "</table>" >> ${V_EMAIL_BODY}
echo "</body>" >> ${V_EMAIL_BODY}
echo "</html>" >> ${V_EMAIL_BODY}
#--Below code will be used to send email notification
export V_CONTENT="${V_EMAIL_BODY}"
(
echo "Subject: Employees Report"
echo "To: ${V_MAIL_TO}"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
echo ${V_CONTENT}
) | /usr/sbin/sendmail ${V_MAIL_TO}
#-------------------------------------------END OF THE SCRIPT---------------------------------------
Output: Above Script will send the email to the user Director@kw.com with the tabular format. We can use such emails in notifying details with more clarification and readability.
Keep Reading, Keep Learning, Keep Sharing..!!!
I also enjoy reading the comments, but notice that a lot of people should stay on topic to try and add value to the original blog post. I would also http://www.proessaywriting.com/write-my-essay/
ReplyDeleteencourage everyone to bookmark this page to your favorite service to help spread the word. I'll use this information for my essay topics.
This is very informative. thanks for sharing this.
ReplyDeleteReal Racing
Thanks