I'm trying to send some HTML table using Mathematica SendMail function. To do it I wrote this function:
createHTMLTable[list_List] /; Length[Dimensions@list] == 2 :=
Module[{r, head, data}, head = First@list;
data = Rest@list;
head = Map[" <th>" <> ToString[#] <> "</th>\n" &, {head}, {2}];
data = Map[" <td>" <> ToString[#] <> "</td>\n" &, data, {2}];
headData = Join[{head}, data];
r = "<tr>\n" <> StringJoin[##] <> "</tr>\n" & /@ headData // StringJoin;
r = "<!DOCTYPE html>
<html>
<body>
<table border=\"1\">
" <> r <> "
</table>
</body>
</html>"
]
When I send the mail, as in this example:
list = RandomInteger[100000, {10, 3}]
SendMail["From" -> "test@test.com", "To" -> "test@test.com",
"Subject" -> "Sending Email from Mathematica", "Body" -> createHTMLTable[list],
"Server" -> "XXXXX"]
there is no table in the mail, but only the HTML text. Anyone knows how to correct this? Is there another way to do it?
createHTMLTable[list]to a file and then opening it with a browser ? – b.gates.you.know.what Nov 06 '12 at 08:09SendMail. – b.gates.you.know.what Nov 06 '12 at 10:58// StringJointoo much in your code? – Sjoerd C. de Vries Nov 06 '12 at 13:33SendMailworks internally, and it seems that it'll always put atext/plainsection at the beginning of the mail. This is what most email programs will display (first). So it might not be possible to do what you want usingSendMail... I might be wrong though (I can't use WorkBench yet and it's a bit difficult to read the code without syntax highlighting...) – Szabolcs Nov 07 '12 at 22:43