Administer JavaMail on Liberty
We can configure JavaMail on Liberty by adding and configuring elements in the server.xml file.
If we have an external mail server, we 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 used to configure JavaMail on Liberty, see JavaMail-1.5.
- In the server.xml file, add the javaMail-1.5
feature.
After adding the feature, we can call the JavaMail
libraries in any application that runs on the server.
<featureManager> <feature>javaMail-1.5</feature> </featureManager>
- Optional:
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 using the Java Naming and Directory Interface (JNDI).
Note: If we 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>