JavaMail and Internet E-mail
Traditionally when you needed to interact with a mail server from within code, you encoun-
tered a messy collection of socket code containing a lot of string parsing. The code would have
to send a request to the server, wait for the response, and then break down the response to
parse the necessary information. The JavaMail API has provided a clean and easy-to-use Java
interface to design and implement messaging and Internet e-mail solutions.
Internet e-mail is comprised of several standards detailing the format and makeup of a message
that is to be sent across the Internet. Standards, as well as some proposed standards, dictate
how Internet e-mail services handle the messages.
The two types of services that JavaMail offers are the transport and store services. The trans-
port service has several jobs, but we will simply think of it as the service that takes our mes-
sage and sends it to the recipient. The message can make several stops along the way, but the
intricacies of these stops are not within the scope of this topic.
The second type of service that a JavaMail system deals with is the store service. The store
manipulates the persistent storage of messages. The storage of messages is done in what most
of us know as mailboxes : for example, your inbox. JavaMail refers to these mailboxes as fold-
ers because it is possible for one folder to contain other folders, messages, or both. The physi-
cal structure of the folders on a mail server depends on the mail server used to create and
manage them. So, to put it simply, a store service allows you to read and manipulate your fold-
ers and messages.
Store and transport are generic terms used by the JavaMail API to refer to the protocols that
actually implement these services. In the case of Internet e-mail, the most widely used trans-
port protocol is the Simple Mail Transfer Protocol (SMTP). The most widely used protocols
that implement the store service are the Post Office Protocol (POP3) and Internet Message
Access Protocol (IMAP4).
JavaMail provides you with an interface to a messaging system. For it to be useful, you also
require service providers that implement the JavaMail API. Packaged with the JavaMail API,
Sun Microsystems supplies you with both an SMTP and an IMAP service provider. A POP
provider can be downloaded through Sun. These providers are the companies' implementations
of the JavaMail API, designed to interact with each of the different protocols.