You can configure JavaMail on Liberty by adding and configuring elements in the
server.xml file.
About this task
If you have an external mail server, you can use the JavaMail API to send and receive email on applications that are running on a Liberty server. The API allows applications to
interact with the external mail server by providing common store and transport protocols, such as
POP3, IMAP, and SMTP.
Liberty supports JavaMail 1.5. For more information about JavaMail 1.5, see the JavaMail API
documentation.
For information about the elements and attributes that you can use to configure JavaMail on Liberty, see JavaMail-1.5.
Procedure
-
In the server.xml file, add the
javaMail-1.5
feature.
After you add the feature, you can call the JavaMail
libraries in any application that runs on the server.
<featureManager>
<feature>javaMail-1.5</feature>
</featureManager>
- Optional:
If you want to create a javax.mail.Session object, add and configure a
mailSession
element.
After the mail session is configured, the session is created and injected by using the Java™ Naming and Directory Interface (JNDI).
Note: If you use the
standard JNDI context, java:comp/env/mail/exampleMailSession
, configure the
jndiName
attribute as
jndiName="mail/exampleMailSession"
.
<mailSession mailSessionID="examplePop3MailSession"
jndiName="ExampleApp/POP3Servlet/exampleMailSession"
description="POP3 javax.mail.Session"
storeProtocol="pop3"
transportProtocol="smtp"
host="exampleserver.com"
user="iamanexample@example.com"
password="example"
from="smtp@testserver.com">
<property name="mail.pop3.host" value="pop3.example.com" />
<property name="mail.pop3.port" value="3110" />
</mailSession>