简体   繁体   English

Java邮件消息正文为html,但类型为text / plain-阅读html

[英]Java mail message body is html but type is text/plain - read html

The body of the message I receive is html structured but the type of the message says text/plain. 我收到的消息的主体是html结构的,但是消息的类型为text / plain。 In javax.mail getContent() returns plain text instead of html structured text. 在javax.mail中,getContent()返回纯文本而不是html结构化文本。 Even getBodyPart() returns just text. 甚至getBodyPart()也只返回文本。

Is there a way of actually extracting the html formatted message body from an email message marked as text/plain? 有没有一种方法实际上可以从标记为文本/纯文本的电子邮件中提取html格式的消息正文?

Object content = inMessage.getContent();
MimeMultipart mimeMultipart = (MimeMultipart) content;
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
String cnt = (String) bodyPart.getContent());

cnt is a plain text instead of being html formatted. cnt是纯文本,而不是html格式。 I know it is html because Outlook reads it as html and ViewSource in Outlook is html email. 我知道它是html,因为Outlook将其读取为html,而Outlook中的ViewSource是html电子邮件。

Thank you 谢谢

The multipart message might be a multipart/alternative that includes both the plain text and html parts. 多部分消息可能是包含纯文本和html部分的多部分/替代消息。 See this JavaMail FAQ entry . 请参阅此JavaMail FAQ条目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM