Java邮件Api不返回所有邮件
嗨,我正在尝试获取Gmail收件箱中的所有邮件,但它并没有返回所有邮件。它会返回几封太旧的邮件。不是最新的。我正在使用以下代码进行测试:Java邮件Api不返回所有邮件,java,gmail,jakarta-mail,Java,Gmail,Jakarta Mail,嗨,我正在尝试获取Gmail收件箱中的所有邮件,但它并没有返回所有邮件。它会返回几封太旧的邮件。不是最新的。我正在使用以下代码进行测试: public class ReadEmail { public static void check(String host, String storeType, final String user, final String password) { try { // create properties fie
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);
}
}
我没有发现我的代码中有什么错误。我已经完成了给定的其他设置
我还想只收到主标签邮件。如何在我的代码中应用选项卡级过滤器
在使用IMAP服务器而不是POP服务器之后,它工作得很好。我不知道原因,但它在IMAP服务器上运行良好。摘自 问:为什么我在使用POP3访问Gmail时看不到我所有的信息 答:Gmail的设置可以控制你的哪些信息可用 通过POP3协议。请参阅Gmail设置页面以更改设置 配置您的Gmail帐户 关于POP3: POP3是访问单个邮箱的非常有限的协议。它的功能远不如IMAP
主选项卡?如果你说的是gmail,请用一个标记来指定它。@Clijsters:是的,我正在用gmail进行尝试。