我有一个callProcedure类,它有方法getProductwiseCount。
通过callprocedure类我正在调用另一个类的sendMail方法。我想从html中的hashmap生成键和值对的动态表,并将其附加到邮件中。我该怎么做?
public HashMap<Long, String> getProductwiseCount() {
return ProductwiseCount;
}
答案 0 :(得分:0)
很容易将html添加到电子邮件正文中。只需创建要添加到正文中的HTML并设置为邮件正文部分,请选中:
https://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/
答案 1 :(得分:0)
I did it by pre-generating html in callProcedure class. Save it in to String and passed it in a sendEmail method.
String text=
"<table width='100%' border='1' align='center'>"
+ "<tr align='center'>"
+ "<td><b>Product Name <b></td>"
+ "<td><b>Count<b></td>"
+ "</tr>";
for (Map.Entry entry : ProductwiseCount.entrySet()) {
System.out.println(entry.getKey() + " :" + entry.getValue());
text=text+"<tr align='center'>"+"<td>" + entry.getValue() + "</td>"
+ "<td>" + entry.getKey() + "</td>"+"</tr>";
}
sendMail.sendMail(host, port, to, from,text);