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

爱⌒轻易说出口 提交于 2019-12-13 02:59:32

问题


The body of the message I receive is html structured but the type of the message says text/plain. In javax.mail getContent() returns plain text instead of html structured text. Even getBodyPart() returns just text.

Is there a way of actually extracting the html formatted message body from an email message marked as text/plain?

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. I know it is html because Outlook reads it as html and ViewSource in Outlook is html email.

Thank you


回答1:


The multipart message might be a multipart/alternative that includes both the plain text and html parts. See this JavaMail FAQ entry.



来源:https://stackoverflow.com/questions/16772105/java-mail-message-body-is-html-but-type-is-text-plain-read-html

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