简体   繁体   中英

Reading mails from folder in yahoo by Javamail

Hi i am having problem with reading mails from manually created folder.

i can read mails from INBOX. but when i try to read mail from other than inbox it is giving error.

I hope stackoverflow will give solution. Thanks in advance...

Error Message:

Exception in thread "main" javax.mail.FolderNotFoundException: folder is not INBOX at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:183) at MailPop3.main(MailPop3.java:24)

My Code:

Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties);
Store store = session.getStore("pop3");
store.connect(host, user, password);
Folder inbox = store.getFolder("MyPersonalFolder");
inbox.open(Folder.READ_ONLY);

// search for all "unseen" messages
Flags seen = new Flags(Flags.Flag.SEEN);
FlagTerm unseenFlagTerm = new FlagTerm(seen, false);
Message messages[] = inbox.search(unseenFlagTerm);

Hope you are using POP. By default POP points to INBOX only. As per POP3Folder ,

A POP3 Folder (can only be "INBOX"). See the com.sun.mail.pop3 package documentation for further information on the POP3 protocol provider.

To access custom folders you require to use IMAPFolder .

This may sound weird, but I guess if you want to make your custome folder and use it in the code then you need to name it "Store", then it will work. Worked for me....took 3 hrs to research...hope works for you too

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM