问题
I am sending an e-mail using JavaMail and I want to put my message data into a table that will be embedded in the e-mail. The person receiving the message will see the table with the filled in data. How do I go about doing this?
回答1:
I guess you mean HTML table?
StringBuilder sb = new StringBuilder();
sb.append("<html><body><table><tr><td>Bubu<td>Lala</tr></table></body></html>");
MimeMessage msg = ...;
msg.setContent(sb.toString(), "text/html");
回答2:
Java Html mail
MimeMessage message =mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, false, "utf-8");
String htmlMsg = "<body><h4 style='color:green;'> Dear <b style='color:red;'>" + userName.getFirstName() + "</b>,"
+ "\n Your produce information is successfully uploaded with following details, <br><table>"
+ "<tr><td>Item Name </td><td> " + produce.getItemName() + "</td></tr>"
+ "<tr><td>Units </td><td> " + produce.getMinUnits() + "</td></tr>"
+ "<tr><td>Last date </td><td> " + produce.getLastDate() + "</td></tr>"
+ "</h4</body>";
message.setContent(htmlMsg, "text/html");
helper.setTo(emailId);
helper.setSubject(subject);
result="success";
mailSender.send(message);
} catch (MessagingException e) {
throw new MailParseException(e);
}finally {
if(result !="success"){
result="fail";
}
}
来源:https://stackoverflow.com/questions/4719367/tables-using-javamail