我无法检索“multipart/MIXED”邮件的正文内容...
这就是我用来阅读邮件的方式......
private String read(Message message) throws MessagingException, IOException {
String result = message.getContentType().toString() + " Unable to read";
if (message instanceof MimeMessage) {
MimeMessage m = (MimeMessage) message;
Object contentObject = m.getContent();
if (contentObject instanceof Multipart) {
BodyPart clearTextPart = null;
BodyPart htmlTextPart = null;
Multipart content = (Multipart) contentObject;
int count = content.getCount();
for (int i = 0; i < count; i++) {
BodyPart part = content.getBodyPart(i);
if (part.isMimeType("text/plain")) {
clearTextPart = part;
break;
} else if (part.isMimeType("text/html")) {
htmlTextPart = part;
}
}
if (clearTextPart != null) {
result = (String) "<html><body>"
+ clearTextPart.getContent() + "</body></html>";
} else if (htmlTextPart != null) {
String html = (String) htmlTextPart.getContent();
result = android.text.Html.fromHtml(html).toString();
}
} else if (contentObject instanceof String) {
String html = (String) contentObject;
result = html;
} else {
result = "not found";
}
}
return result;
}
正如您所看到的问题是,邮件甚至不会通过条件(message instanceof MimeMessage) ...
“multipart/MIXED”邮件的输出是:
multipart/MIXED; boundary=20cf306..... Unable to read
最佳答案
public static String processBody( > Part p < , String operacao)
} else if (p.isMimeType("multipart/*")) {
*** MimeMessage m = (MimeMessage) p; ***
Multipart mp = (Multipart) m.getContent();
for (int i = 0; i < mp.getCount(); i++) {
t = processBody(mp.getBodyPart(i), operacao);
if (t != null)
return t;
}
}
关于javamail 无法读取多部分/混合邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22963026/