문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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";
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top