java - How to get the list of available folders in a mail account using JavaMail -


i using javamail api connect personal account. have list of folders (labels) in gmail account created + default folders inbox, drafts etc. how can list available folders (the default , user created)?

i can access particular folder using api: folder inbox = store.getfolder("inbox");. there other api list of folders available in mail account?

here code works. give handle labels. go deeper in folder, may perform folder.list() or can use store.getdefaultfolder().list("*") retrieve folders , sub-folders suggested in other answer.

properties props = system.getproperties(); props.setproperty("mail.store.protocol", "imaps"); session session = session.getdefaultinstance(props, null); store store = session.getstore("imaps"); store.connect("imap.gmail.com", "yourmailid@gmail.com", "ur_p@zzwrd"); system.out.println(store);  folder[] f = store.getdefaultfolder().list(); for(folder fd:f)     system.out.println(">> "+fd.getname()); 

output:

>> inbox
>> personal
>> receipts
>> travel
>> work
>> [gmail]


old answer

please note not correct, it's rightly pointed in this answer dkarp

these should do:

http://java.sun.com/products/javamail/javadocs/javax/mail/store.html#getsharednamespaces%28%29

http://java.sun.com/products/javamail/javadocs/javax/mail/store.html#getusernamespaces%28java.lang.string%29


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -