嗨我想獲取Gmail收件箱的所有郵件,但它沒有返回所有郵件。它返回的郵件太舊了。不是最新的。我用下面的代碼測試:Java郵件Api不返回所有郵件
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);
}
}
我沒有得到什麼是錯在我的代碼。我已經完成了其他設置,如here。
我也想只獲得主要選項卡郵件。如何在我的代碼中應用選項卡級別篩選器?
主要選項卡?如果你正在談論Gmail,請用標籤指定它。 – Clijsters
@Clijsters:是的,我正在嘗試使用Gmail。 –