Introduction
This
chapter describes how to manage email in your servlets using the
JavaMail and JavaBeans Activation
Framework (JAF)
APIs. JavaMail
provides Java classes for dealing with most aspects of creating,
sending, and accessing email. The JAF is a separate API for handling
the datatypes and Multipurpose Internet Mail Extension (MIME) types
you may encounter when generating email, such as the many different
kinds of file attachments. Both of these APIs are a part of the
Java 2 Enterprise
Edition (J2EE) platform.
JavaMail models an email system with classes that represent
mail sessions (the
javax.mail.Session class),
message stores
(the javax.mail.Store class), folders (the
javax.mail.Folder
class, such as the INBOX folder), email
messages (javax.mail.Message), and email addresses
(the javax.mail.internet.InternetAddress
class) . For example, an email message is similar
to a JavaBean, with setter methods to build the various message
components (e.g., setFrom( ),
setRecipients( ), setSubject(
), etc.).
The following recipes show how to manage basic email messaging using
a single servlet, as well as methods for separating the
responsibility for emailing and handling HTTP requests into JavaBeans
and servlets.
 |