Jakarta Mail
2.0
1.6
1.5

This feature allows applications to use the Jakarta Mail 2.0 API.

Enabling this feature

To enable the Jakarta Mail 2.0 feature, add the following element declaration into your server.xml file, inside the featureManager element:

<feature>mail-2.0</feature>

Example

Send email to and receive email from applications

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

<mailSession>
    <mailSessionID>gmailSMTPSession</mailSessionID>
    <jndiName>ExampleMail/SMTPSender/gmailSMTPSession</jndiName>
    <description>My Gmail SMTP Session</description>
    <storeProtocol>imaps</storeProtocol>
    <transportProtocol>smtp</transportProtocol>
    <host>smtp.gmail.com</host>
    <user>[email protected]</user>
    <password>yourpassword</password>
    <from>[email protected]</from>
    <property name="mail.imap.host" value="imap.gmail.com" />
    <property name="mail.smtp.port" value="587" />
    <property name="mail.smtp.auth" value="true" />
    <property name="mail.smtp.starttls.enable" value="true" />
</mailSession>

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 jakarta.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

  • jakarta.mail

  • jakarta.mail.event

  • jakarta.mail.internet

  • jakarta.mail.search

  • jakarta.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-18.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.

io.openliberty.mail-2.0; type="osgi.subsystem.feature"