我有一个类 callProcedure,它有方法 getProductwiseCount。
通过 callprocedure 类,我正在调用另一个类的 sendMail 方法。我想从 html 中的 hashmap 的键和值对生成动态表,并将其附加在邮件中。我该怎么做?
public HashMap<Long, String> getProductwiseCount() {
return ProductwiseCount;
}
最佳答案
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);
关于java - 如何使用java在电子邮件正文中发送动态html表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108157/