Sending and receiving email from a program is easy with Java. If you are writing
an applet, you can simply trick the browser into composing and sending
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
Transport is a way of
Message from your
application into the network or Internet. A
Store represents stored email messages and can
be used to retrieve them as
objects. That is, a
Store is the
inverse of a
Transport, or, looked at
another way, a
Transport is for
sending email and a
Store is for
reading it. One other class,
is used to obtain references to the appropriate
Transport objects that you need to use.
Being an extension, the JavaMail package must be downloaded separately from Sun’s web site and is not part of the core API. It’s worth it, though. 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. JavaMail is also included in the Java 2 Enterprise Edition (J2EE), so if you have J2EE you do not need to download JavaMail.
Finally, as you might have guessed from Chapter 16, it’s not that big a stretch to write code that contacts an SMTP server yourself and pretends to be a mail program. Hey, why pretend? ...