问题
The code below uses javamail API to access gmail,
String host = "pop.gmail.com";
int port = 995;
Properties properties = new Properties();
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
final javax.mail.Session session = javax.mail.Session.getInstance(properties);
store = session.getStore("pop3s");
store.connect(host, port, mCredentialaNme, mCredentialApss);
// ***************************************************************
Folder personalFolders[] = store.getDefaultFolder().list( "*" );
// ***************************************************************
for (Folder object : personalFolders) {
// ***********************************
System.out.println( object.list("*") );
// ***********************************
if ((object.getType() & javax.mail.Folder.HOLDS_MESSAGES) != 0){
object.open(Folder.READ_ONLY);
Message messes[] = object.getMessages();
System.out.println(object.getFullName());
System.out.println("====================");
for (Message object1 : messes) {
System.out.println(object1.getFrom() + " - " + object1.getSubject());
}
object.close(false);
}
}
if (store.isConnected()) {
store.close();
}
The trouble is that this code only lists the INBOX folder whereas there are no less than 20 labels defined. What should be done to get the code to list/access these nested folders/labels?
回答1:
Don't use POP, use IMAP if you want labels/folders.
As noted in the javamail docs, due to the nature of the POP protocol, a POP message store always
Contains only one folder, "INBOX".
来源:https://stackoverflow.com/questions/5925944/how-to-retrieve-gmail-sub-folders-labels-using-pop3