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 ...
Get Java Enterprise in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.