Jakarta Mail
Jakarta Mail is a Jakarta EE API used to send and receive email via SMTP, POP3 and IMAP. Jakarta Mail is built into the Jakarta EE platform, but also provides an optional package for use in Java SE.
The current version is 2.1.3, released on February 29, 2024. Another open source Jakarta Mail implementation exists, which -while supporting only the obsolete JavaMail 1.3 specification- provides the only free NNTP backend, which makes it possible to use this technology to read and send news group articles.
As of 2019, the software is known as Jakarta Mail, and is part of the Jakarta EE brand. The reference implementation is part of the project.
Maven coordinates of the relevant projects required for operation are:
- mail API: jakarta.mail:jakarta.mail-api:2.1.3
- mail implementation: org.eclipse.angus:angus-mail:2.0.3
- multimedia extensions: jakarta.activation:jakarta.activation-api:2.1.3
Licensing
Jakarta Mail is hosted as an open source project on Eclipse.org under its new name Jakarta Mail.Most of the Jakarta Mail source code is licensed under the following licences:
- EPL-2.0
- GPL-2.0 with Classpath Exception license
- The source code for the demo programs is licensed under the BSD license
Examples
package org.wikipedia.examples;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.Properties;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
// Send a simple, single part, text/plain e-mail
public class TestEmail
Sample Code to Send Multipart E-Mail, HTML E-Mail and File Attachments
package org.wikipedia.examples;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;
import java.util.Properties;
import jakarta.activation.DataHandler;
import jakarta.activation.DataSource;
import jakarta.activation.FileDataSource;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.Multipart;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMultipart;
public class SendMailUsage