Java邮件消息正文为html

Java邮件消息正文为html

本文介绍了Java邮件消息正文为html,但类型为text/plain-阅读html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的邮件正文是html结构的,但是邮件的类型为text/plain.在javax.mail中,getContent()返回纯文本而不是html结构化文本.甚至getBodyPart()都只返回文本.

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.

有没有一种方法可以从标记为文本/纯文本的电子邮件中实际提取html格式的邮件正文?

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是纯文本,而不是html格式.我知道它是html,因为Outlook会将其读取为html,而Outlook中的ViewSource是html电子邮件.

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.

谢谢

推荐答案

多部分消息可能是包含纯文本和html部分的多部分/替代消息.请参见此JavaMail常见问题解答条目.

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

这篇关于Java邮件消息正文为html,但类型为text/plain-阅读html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 20:10