This feature allows applications to interact with an external mail server by using the JavaMail 1.5 API, which provides common store and transport protocols, such as POP3, IMAP, and SMTP.

Enabling this feature

To enable the JavaMail 1.5 feature, add the following element declaration into your server.xml file, inside the featureManager element:



Send email to and receive email from applications

You can call the JavaMail libraries in any application that runs on the server to send and receive emails. Create a javax.mail.Session object by adding and configuring a mailSession element. To enable the following configuration, in addition to enabling the JavaMail feature, you must also enable the Java Naming and Directory Interface (JNDI) feature in your server.xml file:

    <description>My Gmail SMTP Session</description>
    <user>[email protected]</user>
    <from>[email protected]</from>
    <property name="" value="" />
    <property name="mail.smtp.port" value="587" />
    <property name="mail.smtp.auth" value="true" />
    <property name="mail.smtp.starttls.enable" value="true" />

This example mail session is configured so that it can be used for both the Simple Mail Transfer Protocol (SMTP) and the Internet Message Access Protocol (IMAP) on Gmail. After you configure the mailSession element, the mail session is created and injected by using JNDI. The name of the WAR file is ExampleMail, the class name is SMTPSender, and the name of the javax.mail.Session object is gmailSMTPSession. If you use the standard JNDI context, java:comp/env/mail/gmailSMTPSession, specify the jndiName attribute as jndiName="mail/gmailSMTPSession".

Feature configuration elements

Standard API packages provided by this feature

  • javax.mail

  • javax.mail.event

  • javax.mail.internet


  • javax.mail.util

Third-party API packages provided by this feature

  • com.sun.mail

  • com.sun.mail.auth

  • com.sun.mail.handlers

  • com.sun.mail.iap

  • com.sun.mail.imap

  • com.sun.mail.imap.protocol

  • com.sun.mail.pop3

  • com.sun.mail.smtp

  • com.sun.mail.util

  • com.sun.mail.util.logging

Supported Java versions

  • JavaSE-1.8

  • JavaSE-11.0

  • JavaSE-17.0

  • JavaSE-20.0

Features that enable this feature

Developing a feature that depends on this feature

If you are developing a feature that depends on this feature, include the following item in the Subsystem-Content header in your feature manifest file.; type="osgi.subsystem.feature"