java 使用 JavaMail 的表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4719367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:42:04  来源:igfitidea点击:

Tables using JavaMail

javajavamailjavax.mail

提问by Graham

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?

我正在使用 JavaMail 发送电子邮件,并且我想将我的消息数据放入一个将嵌入电子邮件中的表中。接收消息的人将看到填有数据的表格。我该怎么做?

回答by Jochen Bedersdorfer

I guess you mean HTML table?

我猜你是说 HTML 表格?

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");

回答by Umapathi

Java Html mail

Java Html 邮件

    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";
        }
    }