I am trying to generate and send html files by attaching to email body. I tried using awk for generating and sending one file. eg. the input file MARTINI has these records:
1554894,2015-04-16,00:21:52,processes.martini_gsicorptradeeventoutput.instancecount,0,1,UP
1554793,2015-04-15,22:03:52,processes.martini_gsicorptradeeventoutput.instancecount,2,0,DOWN
and I have this awk in a file named HTML:
awk 'BEGIN {
FS=","
print "MIME-Version: 1.0"
print "To:lijo@abc.com"
print "From:lijo@abc.com"
print "Subject: Health check"
print "Content-Type: text/html"
print "Content-Disposition: inline"
print "<HTML>""<TABLE border="1"><TH>Ref_id</TH><TH>EOD</TH><TH>Time</TH><TH>Process</TH><TH>Desc</TH><TH>Instance</TH><TH>Status</TH>"
}
{
printf "`<TR>`"
for(i=1;i<=NF;i++)
printf "`<TD>%s</TD>`", $i
print "`</TR>`"
}
END {
print "`</TABLE></BODY></HTML>`"
} ' /home/martini > /home/martini_html
Later I send this file through email cat MARTINI_HTML | /usr/sbin/sendmail -t
. This works until here. But now I have 2 new tasks:
How to convert multiple files Say MARTINI1, MARTINI2 … etc into html files and how to attach them in email body as separate table block and not as a single table?
Some mail utilities such as mailx
is not available.
Best Answer
You'll need to set the content-type to multipart/mixed and define a boundary (separator string), and add an instance of the string between each file. I provided a few examples of this a while back in this post: Using just Bash and Sendmail to send multiple input files and / or a pipe as attachments in an email
A bit of the code: