Java Reference
In-Depth Information
CHAPTER 3
Receiving Mail
Receiving mail is considerably more complex than sending it. SMTP uses only 14 dif‐
ferent commands, and a simple email client can be implemented with just five of them.
POP3, however, has 12 commands, almost all of which a client must be able to handle;
IMAP4 has 24 different commands.
The JavaMail API is designed to retrieve messages from an IMAP or perhaps an NNTP
server. That is, it assumes the server can return headers separate from the messages they
belong to, search through mailboxes, provide the storage for the messages rather than
the client, and so forth. The JavaMail API provides less of what you need for client-
oriented mail access protocols, such as POP3, that assume the client stores and manages
the mail archive; but it still gives you the tools you need to download the mail from the
server. You just have to implement your own storage system on the client. (You can
check out the experimental POP3RemoteStore if you want to both store and retrieve.)
We'll begin with the simpler POP3 protocol, then move on to IMAP. From the per‐
spective of JavaMail, IMAP can be viewed largely as POP plus some commands for
manipulating folders. For simple programs that operate only on the INBOX folder, POP
and IMAP clients are more or less the same.
There are about 12 steps to reading a remote mailbox (the number of steps can vary a
little, since some steps are optional or can be combined with or replaced by others):
1. Set up the properties you'll use for the connection.
2. Construct the Authenticator you'll use for the connection.
3. Get a Session object with Session.getInstance() .
4. Use the session's getStore() method to return a Store .
5. Connect to the store.
6. Get the INBOX folder from the store with the getFolder() method.
 
Search WWH ::




Custom Search