Jakarta Mail2.12.01.61.5
This feature allows applications to use the Jakarta Mail 2.1 API.
If you are updating your application from using the mail-2.0
feature to using the mail-2.1
feature, changes in API behavior might require you to update your application code. For more information, see Differences between Jakarta Mail 2.1 and 2.0.
Enabling this feature
To enable the Jakarta Mail 2.1 feature, add the following element declaration into your server.xml
file, inside the featureManager
element:
<feature>mail-2.1</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"
.
Standard API packages provided by this feature
jakarta.activation
jakarta.annotation
jakarta.annotation.security
jakarta.annotation.sql
jakarta.mail
jakarta.mail.event
jakarta.mail.internet
jakarta.mail.search
jakarta.mail.util
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.1; type="osgi.subsystem.feature"