JavaMail
2.1
2.0
1.6
1.5

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:

<feature>javaMail-1.5</feature>

Example

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:

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

  • javax.annotation

  • javax.annotation.security

  • javax.annotation.sql

  • javax.mail

  • javax.mail.event

  • javax.mail.internet

  • javax.mail.search

  • 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-21.0

  • JavaSE-22.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.

com.ibm.websphere.appserver.javaMail-1.5; type="osgi.subsystem.feature"