它只读取收件箱中的新邮件,而我想读取所有邮件。 如何实现呢?
Folder folderInbox = store.getFolder("INBOX");
folderInbox.open(Folder.READ_ONLY)
Message[] arrayMessages = folderInbox.getMessages();
答案 0 :(得分:0)
您可以尝试使用方法Message[] messages = inbox.getMessages(startMessage, endMessage);
代替Message[] arrayMessages = folderInbox.getMessages();
这里startMessage和endMessage是整数值。这里有一个很好的例子 - enter link description here
Folder inbox = store.getFolder("inbox");
inbox.open(Folder.READ_WRITE); // Folder.READ_ONLY
int messageCount = inbox.getMessageCount();
System.out.println("Total Messages" + messageCount);
int startMessage = messageCount - 5;
int endMessage = messageCount;
if (messageCount < 5) {
startMessage = 0;
}
Message[] messages = inbox.getMessages(startMessage, endMessage);