Hi,
I was working on getting an HTML file in the mail body along with attaching a "csv" file to the mail.
Below are the 2 parts of the code.
I need help with the second part where I'm sending the mail. The HTML file as an attachment is perfect without any issues and with proper formatting.
The HTML file as a body however with the code below is creating extra block in the HTML table output seen int he mail body.
Other thing that comes int he body is the "boundary variable" at the end of the mail.
So the end of the mail is like below where you see "---asdfghjkl". I tried removing and adding the "---asdfghjkl" from the code and in various places and it had different results where sometimes the body doesn't display the HTML table and just in one line. Can you please help me get rid of the extra line there or can point out what I may be doing wrong? I referred to many code bases here but couldn't find a solution.
I'm working on AIX - 6.1.0.0
Thank You.
XZY Team.
---asdfghjkl
###############################################################################
### Code to create HTML
###############################################################################
awk 'BEGIN{
printf "<BR>"
printf "<BR>"
printf "<FONT SIZE=4><CENTER><B> XXXXX $DATE</B></CENTER></FONT>"
printf "<BR>"
FS=","
print "<HTML><HEAD><TITLE> Table header </TITLE></HEAD><BODY><TABLE border = "4" BORDERCOLOR =BLACK cellpadding="2" ALIGN=CENTER WIDTH=100%>"
print "<TR><TD width=90 ALIGN=CENTER> <B> Col 1 </B></TD>"
print "<TD width=90 ALIGN=CENTER> <B> Col 2 </B></TD>"
print "<TD width=90 ALIGN=CENTER> <B> Col 3 </B></TD>"
print "<TD width=90 ALIGN=CENTER> <B> Col 4 </B></TD></TR>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
printf "<TR><TD></TD></TR></TABLE>"
printf "<BR>"
printf "<FONT SIZE=3><LEFT>additional comments.</CENTER></FONT>"
printf "<BR>"
printf "<FONT SIZE=3 COLOR=BLUE><LEFT>Thank You.</CENTER></FONT>"
printf "<FONT SIZE=3 COLOR=BLUE><LEFT>XYZ Team.</CENTER></FONT>"
printf "</BODY></HTML>"
}' /tmp/test_file.dat > /tmp/test_file.html
###############################################################################
### Code to attach file and send mail with HTML
###############################################################################
export MAILTO="ABC@XYZ.com"
export SUBJECT="Mail Subject"
export BODY="/tmp/test_file.html"
export ATTACH="/tmp/test_file.csv"
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-asdfghjkl"'
echo '---asdfghjkl'
echo 'Content-Type: text/plain charset=US-ASCII; name="'$(basename $ATTACH)'"'
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo '---asdfghjkl'
cat $ATTACH
echo '---asdfghjkl'
echo "Content-Type: text/html charset=US-ASCII;"
echo "Content-Disposition: inline"
echo '---asdfghjkl'
cat $BODY
echo '---asdfghjkl'
) | /usr/sbin/sendmail $MAILTO
###############################################################################
How does the HTML you get, differ from the HTML in your code?
Actual HTML file
cat test_file.html
<BR><BR><FONT SIZE=4><CENTER><B>XXXXX</B></CENTER></FONT><BR><HTML><HEAD><TITLE> Title Header </TITLE></HEAD><BODY><TABLE border = 4 BORDERCOLOR =BLACK cellpadding=2 ALIGN=CENTER WIDTH=100%>
<TR><TD width=90 ALIGN=CENTER> <B> Col 1 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 2 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 3 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 4 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 5 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 6 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 7 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 8 </B></TD>
<TD width=90 ALIGN=CENTER> <B> Col 9 </B></TD></TR>
<TR><TD>29-04-2015 10:30:32</TD><TD>4940</TD><TD>2734</TD><TD>0</TD><TD>0</TD><TD>358</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 09:30:29</TD><TD>10128</TD><TD>2248</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 08:30:36</TD><TD>0</TD><TD>0</TD><TD>284</TD><TD>35</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 07:30:31</TD><TD>3574</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 06:30:17</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>2091665</TD><TD>0</TD><TD>0</TD><TD>694</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 05:30:33</TD><TD>0</TD><TD>436</TD><TD>0</TD><TD>2090247</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 04:30:26</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>2089482</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 03:30:39</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>445</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 02:30:43</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 01:30:31</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>116</TD><TD>0</TD><TD>0</TD><TD>0</TD></TR>
<TR><TD>29-04-2015 00:30:43</TD><TD>799</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>0</TD><TD>907</TD></TR>
<TR><TD></TD></TR></TABLE><BR><FONT SIZE=3><LEFT>additional comments.</CENTER></FONT><BR><FONT SIZE=3 COLOR=BLUE><LEFT>Thank You.</CENTER></FONT><FONT SIZE=3 COLOR=BLUE><LEFT>XYZ Team.</CENTER></FONT></BODY></HTML>
HTML in the body
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><br><br><font size="4"><center><b>XXXXX</b></center></font><br><html><head><title> Title Header </title></head><body><table border="4" BORDERCOLOR="BLACK" cellpadding="2" align="CENTER" width="100%">
<tr><td width="90" align="CENTER"> <b> Col 1 </b></td>
<td width="90" align="CENTER"> <b> Col 2 </b></td>
<td width="90" align="CENTER"> <b> Col 3 </b></td>
<td width="90" align="CENTER"> <b> Col 4 </b></td>
<td width="90" align="CENTER"> <b> Col 5 </b></td>
<td width="90" align="CENTER"> <b> Col 6 </b></td>
<td width="90" align="CENTER"> <b> Col 7 </b></td>
<td width="90" align="CENTER"> <b> Col 8 </b></td>
<td width="90" align="CENTER"> <b> Col 9 </b></td></tr>
<tr><td>29-04-2015 10:30:32</td><td>4940</td><td>2734</td><td>0</td><td>0</td><td>358</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 09:30:29</td><td>10128</td><td>2248</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 08:30:36</td><td>0</td><td>0</td><td>284</td><td>35</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 07:30:31</td><td>3574</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 06:30:17</td><td>0</td><td>0</td><td>0</td><td>2091665</td><td>0</td><td>0</td><td>694</td><td>0</td></tr>
<tr><td>29-04-2015 05:30:33</td><td>0</td><td>436</td><td>0</td><td>2090247</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 04:30:26</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>2089482</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 03:30:39</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>445</td><td>0</td></tr>
<tr><td>29-04-2015 02:30:43</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 01:30:31</td><td>0</td><td>0</td><td>0</td><td>0</td><td>116</td><td>0</td><td>0</td><td>0</td></tr>
<tr><td>29-04-2015 00:30:43</td><td>799</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>907</td></tr>
<tr><td></td></tr></table><br><font size="3"><LEFT>additional comments.</center></font><br><font size="3" color="BLUE"><LEFT>Thank You.</center></font><font size="3" color="BLUE"><LEFT>XYZ Team.</center></font></body></html>---asdfghjkl
Show me the HTML, all of it, what it should be and what it is. Not what it "looks like".
Got the extra box removed by updating the HTML code
END{
printf "</TABLE>"
printf "<BR>"
instead of
END{
printf "<TR><TD></TD></TR></TABLE>"
printf "<BR>"
Still struggling with the extra "boundary" echo in the mail body.
Try adding a newline before and/or after the --boundary line.
Got it resolved....updated the last peice of code to remove boundary and just have the "echo" as below
cat $ATTACH
echo '---asdfghjkl'
echo "Content-Type: text/html charset=US-ASCII;"
echo "Content-Disposition: inline"
echo '---asdfghjkl'
cat $BODY
echo
) | /usr/sbin/sendmail $MAILTO
###############################################################################