Creating a JavaMail session

The javax.mail.Session object is responsible for managing a user’s mail configuration settings and handling authentication for the individual transports used during the session.

To create platform-independent applications, a JavaMail program can use a resource factory reference to obtain a JavaMail session. A resource factory is an object that provides access to specific resources within a program’s deployed environment using the specific naming conventions defined by JNDI. All resource factory references are organized by resource type in the application’s component environment. For example, JavaMail resource factory references are found in java:comp/env/mail. For more information on using resource factory references, see:

To obtain an initial JNDI naming context for your JavaMail session, create an instance of the javax.naming.InitialContext object. Then call the lookup method to invoke the javax.mail.Session factory reference to obtain a JavaMail session. This session will map to the local mail server as defined for the environment in which your JavaMail program is deployed. See “Deploying JavaMail-enabled applications” for information on specifying your local resources.