问题
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