嗨,我想得到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);
}
}发布于 2017-08-31 09:31:48
取自这里
问:为什么我在用POP3访问Gmail时没有看到我所有的消息? 答: Gmail有一些设置,可以通过POP3协议控制您的哪些消息可用。请参阅Gmail设置页面,以更改Gmail帐户的配置。
关于POP3:
POP3是一种非常有限的访问单个邮箱的协议。它比IMAP能力差得多。
发布于 2017-08-29 12:23:48
在使用IMAP服务器而不是使用POP服务器之后,它工作得很好。我不知道原因,但它在IMAP服务器上运行得很好。
https://stackoverflow.com/questions/45932101
复制相似问题