java - 如何使用java在电子邮件正文中发送动态html表

标签 java html

我有一个类 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/

相关文章:

javascript - 如何从 Div 中找到每个 li 以及如何获取每个 <li> 标签的文本?

javascript - 幻灯片定位问题

javascript - vue组件中的jsp java变量访问

java - org.sonar.api.utils.SonarException : Can not add twice the same measure on org. sonar.api.resources.File

Java 正则表达式@字符串

javascript - ng2 文件上传不允许我在将其从 que 中删除后添加相同的文档

java - 使用 Selenium 断言滚动条的存在(webdriver java cucumber)

Java双缓冲——访问后像

html - CSS 导航间隙

jQuery 移动页面不占用页面的全宽/缩放