gpt4 book ai didi

Java Mail Api 不返回所有邮件

转载 作者:行者123 更新时间:2023-12-02 12:19:01 27 4
gpt4 key购买 nike

您好,我正在尝试获取 Gmail 收件箱的所有邮件,但它没有返回所有邮件。它返回一些太旧的邮件。不是最新的。我正在使用以下代码进行测试:

public class ReadEmail {

public static void check(String host, String storeType, final String user, final String password) {
try {

// create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
Session emailSession = Session.getDefaultInstance(properties);
emailSession.setDebug(true);

// create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");

store.connect(host, user, password);

// create the folder object and open it
Folder emailFolder = store.getFolder("Inbox");
emailFolder.open(Folder.READ_ONLY);

// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);

// close the store and folder objects
emailFolder.close(false);
store.close();

} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

String host = "pop.gmail.com";
String mailStoreType = "pop3";
String username = "****@gmail.com";// change accordingly
String password = "****";// change accordingly

check(host, mailStoreType, username, password);

}
}
  1. 我没有发现我的代码有什么问题。我已经完成了给定的其他设置here

  2. 我也只想获取主要选项卡邮件。如何在我的代码中应用选项卡级过滤器?

最佳答案

取自 here

Q: Why don't I see all my messages when accessing Gmail with POP3?

A: Gmail has settings that control which of your messages are availablevia the POP3 protocol. See the Gmail settings page to change theconfiguration of your Gmail account.

关于 POP3:

POP3 is a very limited protocol for accessing a single mailbox. It is much less capable than IMAP

关于Java Mail Api 不返回所有邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45932101/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com