Java Reference
In-Depth Information
Chapter 16: Using the JavaMail API with JDBC
In This Chapter
In the earlier days of the Internet, e-mail mainly consisted of text messages that were handled using
simple Java applications. As the popularity of e-mail has grown, its capabilities have expanded
dramatically to the point where most e-mails these days are sent in both text and HTML formats and
can include a wide range of different content types. The JavaMail API has been developed to simplify
the task of handling these more complex e-mail messages using Java. This chapter gives a brief
overview of the JavaMail API and illustrates the use of JDBC and JavaMail to send and receive e-mail.
Using E-mail Protocols
The backbone of e-mail is a network of interconnected Simple Mail Transfer Protocol (SMPT) servers,
which store and forward e-mails. To send an e-mail, you connect to your local SMTP server and send
the e-mail using SMTP. The e-mail is then forwarded to the recipient's server and held in the recipient's
e-mail folder. Th e recipient later retrieves the e-mail, usually using the Post Office Protocol (POP). As
the complexity of e-mail messages has grown, so has the need to manage the different data types
contained in e-mail messages. This has led to the development of the Multipurpose Internet Mail
Extensions.
Multipurpose Internet Mail Extensions (MIME)
The Multipurpose Internet Mail Extensions (MIME) define the content of e-mail messages, attachments,
and so on. The MIME data type is defined in a Content-Type header field, used to specify the type and
subtype of data in the body of a message. These are the common MIME types:
 
"text" — used to represent standard text content
 
"multipart" — used to combine several body parts, possibly of differing types, into a single
message
 
"application" — used to transmit application data or binary data
 
"image" — used for transmitting still-image (picture) data
 
"audio" — used for transmitting audio or voice data
 
"video" — used for transmitting video or moving-image data
As a user of the JavaMail API, you are able to retrieve the MIME type from the header and to use it in
deciding how to process the message.
Simple Mail Transfer Protocol (SMTP)
The SMTP is used for sending e-mail to an SMTP server, which your Internet Service Provider (ISP)
usually manages. That SMTP server relays the e-mail message on to the recipient's SMTP server,
where it is held in an e-mail store for the recipient's retrieval. The SMTP is defined in RFC 821,
available at http://www.faqs.org/rfcs/rfc821.html .
Post Office Protocol (POP)
Since the current revision is version of POP is 3, the protocol is also known as POP3. Supporting a
single mailbox for each user, POP3 is the most widely used way to download e-mail. POP3 is defined in
RFC 1939, available at http://www.faqs.org/rfcs/rfc1939.html .
Note
POP3 supports only basic storage and download of e-mails. Features such as tracking
new e-mails are handled by clients such as Eudora.
The next section explains how the JavaMail API works, and how to use it.
Using the JavaMail API
Search WWH ::




Custom Search