Java Mail API Store and folder
by, 04-25-2012 at 09:56 PM (2773 Views)
When session is obtained, connection is made b/w javax.mail.Store & host, authenticator, port, username/password. Store objects which are involved in implementation of specified protocol might be formed by protocol information passage to the getStore() method.
After connecting to store you need to get a folder that holds messages. For POP3, the only folder available is the INBOX but with IMAP, you can have other folders available. For this you can use javax.mail.Folder class….Java Code:// create object of store class. Store store = session.getStore("pop3"); store.connect(host, username, password);
After making connection with store, obtain the folder to hold messages. Folder present for POP3 is inbox however for IMAP other folder might also be there. Use javax.mail.Folder class for this.
Close Store and Folder once all messages have been read.Java Code:Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message message = folder.getMessages();
Java Code:folder.close(booleanValue); store.close();