当我在contentText中读取来自 java.mail 的电子邮件正文时,我首先得到纯文本,然后得到 HTML 文本。即如果发送消息是
<div><b>模拟</b><br />模拟2</div>
contentText 将包含:
模拟 模拟 <div><b>模拟</b><br />模拟 2</div>
下面是我加载 contentText 的代码:
public void setContentText(Multipart multipart) throws MessagingException, IOException {
contentText ="";
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
getBodyToStringPart(bodyPart);
}
}
protected void getBodyToStringPart(BodyPart bodyPart) throws MessagingException, IOException {
String disposition = bodyPart.getDisposition();
if (!StringUtils.equalsIgnoreCase(disposition, "ATTACHMENT")) {
if (bodyPart.getContent() instanceof BASE64DecoderStream
&& bodyPart.getHeader("Content-ID") != null) {
BASE64DecoderStream base64DecoderStream = (BASE64DecoderStream) bodyPart
.getContent();
byte[] byteArray = …Run Code Online (Sandbox Code Playgroud)