View RSS Feed

Java Mail

Java Mail API Store and folder

Rate this Entry
by , 04-25-2012 at 10:56 PM (3042 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.

Java Code:
// create object of store class.
Store store = session.getStore("pop3");
store.connect(host, username, password);
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….

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.

Java Code:
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
Close Store and Folder once all messages have been read.

Java Code:
folder.close(booleanValue);
store.close();

Submit "Java Mail API Store and folder" to Facebook Submit "Java Mail API Store and folder" to Digg Submit "Java Mail API Store and folder" to del.icio.us Submit "Java Mail API Store and folder" to StumbleUpon Submit "Java Mail API Store and folder" to Google

Comments