Chapter 17. Java and Electronic Mail
Sending and receiving email from a program is easy with Java. If you are writing an
applet, you can simply get the browser to compose and send it for you. Otherwise, you can
use the JavaMail Extension (package
javax.mail) to both send and read mail. JavaMail
provides three general categories of classes:
Message, of course, represents one email message. A
Transport is a way of sending a
Message from your application into the network or Internet. A
Store represents stored
email messages and can be used to retrieve them as
Transport is for sending email and a
Store is for reading it.
One other class,
Session, is used to obtain references to the appropriate
Transport objects that you need to use.
The JavaMail package is included in JavaEE and can be downloaded for JavaSE use.
It’s worth it: for the cost of a few minutes’ downloading time, you get the ability to send and
receive electronic mail over a variety of network protocols.
The JavaMail project is hosted on
java.net; the project’s page is at
You can download a JAR file containing al the standard protocol providers (SMTP, IMAP, POP3),,
or an API JAR just to compile against, or download the basic API and download
the protocols individually.
There are Maven artifacts in Maven Central as well; see
http://search.maven.org/#search|ga|1|com.sun.mail. There is a JavaMail ...