Wednesday, April 01, 2009

Sending HTML Mail by way of report !!!

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,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{
print  "<HTML>""<TABLE border="1"><TH>one</TH><TH>two</TH><TH>three</TH><TH>four</TH><TH>five</TH><
printf "<TR>"
printf "<TD>%s</TD>", $i
print "</TR>"
print "</TABLE></BODY></HTML>"
' test.csv > file.html

Step 2) sending the HTML file as inline mail :


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"
) | /usr/sbin/sendmail $MAILTO

No comments: