Sending HTML Mail by way of report !!!
I wanted to do below :
Step 1) Convert .csv comma seperated file to .html file
Step 2) Sending the HTML file as inline mail (had to use sendmail command , mailx wont support sending mail by way of HTML inline):
Step 1) Convert .csv comma seperated file to .html file
CSV file :test.csv: (This need to convert to .html)
EQADM,edtsdb445s4s,832caef0,gpatmon,/bin/ksh,prete Erick Whindleton
EQADM,eqzd56s5s,83cd26bd,gpatmon,/bin/ksh,rete WHINDLETON,KED_RA,none
EQADM,eqzrtshs,8343f9a5,gpatmon,/bin/ksh,hshsrick Whindleton
EQADM,ed876b4c,832cab9c,gpatmon,/bin/ksh,sjsjs Erick Whindleton
EQADM,eq765qa25-phys,83c3802d,gpatmon,/bin/ksh,tsgsgsgWHINDLETON
EQADM,eq234canj1,80c9b573,gpatmon,/bin/ksh,ERICK C WHINDLETON
EQADM,eqznj10-phys,83193e0b,gpatmon,/bin/ksh,Erick Whinrtsrsksksk
EQADM,eqzdsnj2-phys,8338abba,gpatmon,/bin/ksh,ERICK C WHINDLETON
For this I used awk command :
bash-2.03$ awk 'BEGIN{
FS=","
print "<HTML>""<TABLE border="1"><TH>one</TH><TH>two</TH><TH>three</TH><TH>four</TH><TH>five</TH><
TH>six</TH><TH>seven</TH><TH>eight</TH><TH>nine</TH><TH>ten</TH>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
print "</TABLE></BODY></HTML>"
}
' test.csv > file.html
Step 2) sending the HTML file as inline mail :
#!/usr/bin/ksh
export MAILTO=sendmailto@mailid.com
export CONTENT="index.html"
export SUBJECT="Html Format"
(
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT
) | /usr/sbin/sendmail $MAILTO
No comments:
Post a Comment