-
JavaMail with Pop3
I used JavaMail and Pop3 libraries from SUN to finish a simple project.
But I met a problem.
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);
Store store = null;
Folder rf = null;
store = session.getStore("pop3");
host = "pop.mail.yahoo.com";
user = "xxxx";
password = "xxxx";
store.connect(host, user, password);
rf = store.getDefaultFolder();
if (rf instanceof com.sun.mail.pop3.POP3Folder) {
System.out.println("right");
}
System.out.println("\nOK. Folder got");
Message[] msgs = rf.getMessages();
System.out.println(msgs.length);
The msgs.length == 0! , WHY? I used mail.yahoo.com to access, there are 7 mails in the INBOX folder.
BTW , the "right" and "OK. Folder got" are printed.
Could anyone help me out?
Thanks
-
Re: JavaMail with Pop3
I think that it might be the problem that rf is the instance of POP3Folder but it does not
mean that rf is the instance of Folder representing Inbox folder in the POP3 mail server.
Hence, the number of message might be zero. Why do you use getFolder method with
specifying the argument Inbox. You may reference the document of JavaMail API.
good luck
Alfred Wu
-
Re: JavaMail with Pop3
Thank you for your response.
But I have tried to use getFolder("INBOX"),
the msg.length == -1. Why?
-
Re: JavaMail with Pop3
add one instruction, rf.open(Folder.READ_WRITE), before calling rf.getMessages();
and after instruction, store.getFolder(). I guess if it is the case that the folder is not
opened.
good luck