O'Reilly logo

Java Enterprise in a Nutshell, Third Edition by William Crawford, Jim Farley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving Messages

In addition to allowing programs to create and send messages, the JavaMail API also provides facilities to retrieve incoming messages. This is done via a “message store.” For standard Internet mail, the message store is generally held on a mail server and accessed via a mail client protocol.

JavaMail 1.2 and later distributions include message store implementations for POP-3 and IMAP mail client protocols. POP-3 is an older protocol that is still used by most ISPs and many corporate environments. It allows clients to list all available messages, retrieve them, and delete them. POP, which stands for Post Office Protocol, was designed to work like a post office, acting as a central clearinghouse for incoming messages and providing a mechanism to deliver those messages to the recipient.

POP-3 stops at the point of message delivery. IMAP, however, is a newer protocol that allows more complex message handling. IMAP clients can organize messages into different “folders” on the server, based on user commands or built-in server filtering rules. In some implementations, the IMAP server is intended as the final repository for all of a user’s messages. The mail client simply accesses the IMAP folders and retrieves message information as required.

Message Stores

Message stores are accessed via implementations of the Store object. The getStore() method of Session is used to retrieve a Store implementation. getStore() provides a variety of ways to specify the desired message ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required