本文介绍了如何发送 HTML 电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已使用 JMS 在我的 Web 应用程序中成功发送电子邮件,但结果仅以纯文本形式显示.我希望内容能够显示 html.我该怎么做?以下是我所拥有的:
I have successfully sent email in my web application using JMS, but the result only displays in plain text. I want the content to be able to display html. How do I do it? Here is roughly what I have:
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.setText(message);
msg.setSentDate(new Date());
Transport.send(msg);
}catch(MessagingException me){
logger.log(Level.SEVERE, "sendEmailNotification: {0}", me.getMessage());
}
推荐答案
根据 Javadoc,MimeMessage#setText()
设置默认的 MIME 类型 text/plaincode>,而您需要
text/html
.而是使用 MimeMessage#setContent()
代替.
As per the Javadoc, the MimeMessage#setText()
sets a default mime type of text/plain
, while you need text/html
. Rather use MimeMessage#setContent()
instead.
message.setContent(someHtmlMessage, "text/html; charset=utf-8");
有关其他详细信息,请参阅:
For additional details, see:
这篇关于如何发送 HTML 电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!