我已经使用JMS在Web应用程序中成功发送了电子邮件,但是结果仅以纯文本显示。我希望内容能够显示html。我该怎么做?这大致就是我所拥有的:
Message msg = new MimeMessage(mailSession); try{ msg.setSubject("Test Notification"); msg.setRecipient(Message.RecipientType.TO, new InternetAddress(sentTo, false)); String message = "<div style=\"color:red;\">BRIDGEYE</div>"; msg.setContent(message, "text/html; charset=utf-8"); msg.setSentDate(new Date()); Transport.send(msg); }catch(MessagingException me){ logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage()); }
根据Javadoc,在需要时,这些MimeMessage#setText()设置将默认的mime类型设置为。而是使用代替。text/plaintext/htmlMimeMessage#setContent()
MimeMessage#setText()
text/plaintext/htmlMimeMessage#setContent()
message.setContent(someHtmlMessage, "text/html; charset=utf-8");