Chapter 11. JavaMail

The JavaMail APIs provide a platform and protocol-independent framework to build Java-based mail and messaging applications with a particular focus on Internet email. JavaMail can be used to build mail user agent (MUA) programs. This includes such applications as mail clients, but, in an enterprise setting, the primary application for JavaMail might be to add electronic mail capability to existing and new applications. For example, a Java servlet can use JavaMail to implement a web-based mail reading system, to send confirmations and notifications, receive commands from users, or even communicate with middleware.

Sun Microsystems, Inc. included a basic SMTP email class in the first version of the JDK. However, because this class could only send email, and was only available with Sun’s implementation of the JDK, developers who wished to include more advanced electronic mail capability into their applications generally needed to start from scratch. The JavaMail API, first introduced in early 1998 and now in Version 1.2, fills this niche, giving Java applications a complete mail and messaging framework.

Frankly speaking, the JavaMail API isn’t really an email API at all. The JavaMail classes provide an interface to a generic set of messaging functions for creating, storing, and transporting messages. Developers can extend these classes to implement custom transport protocols and develop standardized mail applications. As an add-on, the distribution includes implementations ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.