Tables using JavaMail

二次信任 提交于 2019-12-20 03:24:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!