0
我想從以下java代碼讀取電子郵件正文從Outlook。如果電子郵件包含表格,我該如何正確閱讀?使用 代碼是如何通過表格Java代碼讀取電子郵件?
// Methods to get Email message content.
private String getTextFromMessage(Message message) throws Exception {
String result = "";
if (message.isMimeType("text/plain")) {
result = message.getContent().toString();
} else if (message.isMimeType("multipart/*")) {
MimeMultipart mimeMultipart = (MimeMultipart)message.getContent();
result = getTextFromMimeMultipart(mimeMultipart);
}
result = removeHyperTextContent(result);
return result;
}
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception
{
String result = "";
int count = mimeMultipart.getCount();
for (int i = 0; i < count; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result = result + "\n" + bodyPart. getContent();
break; }
if (bodyPart.isMimeType("text/html")) {
String html = (String)bodyPart.getContent();
result = result + "\n" + html;
} else if ((bodyPart.getContent() instanceof MimeMultipart)) {
result = result + getTextFromMimeMultipart((MimeMultipart)bodyPart.getContent());
break; //This is added to break after recursive call, otherwise it fetches the content from next MultiPart.
}
}
result = removeHyperTextContent(result);
return result;
}
1. Body of original body text 2 . Out put string I got
在問題中你不清楚你要找什麼輸出。它看起來像你正在得到表的確切輸出。如果您將電子郵件作爲字符串輸出,那就好像它會得到。 – drelliot
。謝謝您的回覆。我想在瀏覽器上向用戶顯示整條消息。我怎樣才能做到這一點?提前致謝.. – Harishfysx