Jakarta Mail Tutorial

On January 21, 2020
14min read
Alfrick Opidi Web developer & freelancer writer

The Jakarta Mail API offers a robust framework for creating email messaging applications using the popular Java programming language. With the API, you can send and receive emails via Simple Mail Transfer Protocol (SMTP), Internet Message Access Protocol (IMAP), or Post Office Protocol (POP).

What is Jakarta Mail?

For a long time, the Java Enterprise Edition (commonly known as Java EE) has been the de facto platform for developing mission-critical applications. 

Recently, in order to stir the creation of cloud-native applications, several prominent software vendors joined hands to transfer Java EE technologies to the Eclipse Foundation, which is a not-for-profit organization tasked with stewarding the activities of the Eclipse open source software community.

Consequently, Java EE has been rebranded to Jakarta EE. And as of July 2018, the mail package that was known as JavaMail API has been further enhanced by the Eclipse Foundation and renamed to Jakarta Mail API

In spite of the name change, all the main classes and properties definitions still remain the same for both Jakarta Mail and JavaMail.

In this article, we’re going to illustrate how to utilize the Jakarta Mail API to send different types of email messages. 

Getting started with Jakarta Mail

To get started using Jakarta Mail, you need to download the jakarta.mail.jar file available on the Jakarta Mail project page on GitHub. Then, you should set your CLASSPATH environment variable to consist of the downloaded “jakarta.mail.jar” file and the current directory.

For example, on a Windows machine, if you have downloaded the file to the /you/you/download/ directory, the following would work:

      set CLASSPATH=%CLASSPATH%;c:\download\jakarta.mail.jar;.

Besides, since the jakarta.mail.jar file is available on the Maven repository, you can also add it to your environment with Maven dependencies.

  <dependencies>
        <dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>jakarta.mail</artifactId>
    <version>2.0.1</version>
</dependency>
        </dependencies>

Note: The latest release of Jakarta Mail at the time of the most recent article update is 2.0.1.

Jakarta Mail API Core Classes

The Jakarta Mail API has a wide range of classes and interfaces that can be used for sending, reading, and performing other actions with email messages—just like in a typical mailing system.

Although there are several packages in the Jakarta Mail Project, two of the most frequently used ones are javax.mail and javax.mail.internet. 

The javax.mail package provides classes that model a mail system and the javax.mail.internet package provides classes that are focused on Internet mail systems.

Here is a description of the core classes in each of the packages:

1. javax.mail.Session

The Session class, which is not subclassed, is the top-level class of the Jakarta Mail API. It’s a multi-threaded object that acts as the connection factory for the Jakarta Mail API. Apart from collecting the API’s properties and defaults, it is responsible for configuration settings and authentication.

To get an instance of the Session class, you can call either of the following two methods:

  • getDefaultInstance(), which returns the default session
  • getInstance(), which returns a new session

2. javax.mail.Message

The Message class is an abstract class that models an email message while its subclasses support the actual implementations. Usually, its MimeMessage subclass (javax.mail.internet.MimeMessage) is used for crafting the details of the email message to be sent. A MimeMessage object is an email message that uses the MIME (Multipurpose Internet Mail Extension) formatting style.

Here are some of the commonly used methods of the MimeMessage class:

  • setFrom(Address addresses)—it’s used to set the “From” header field.
  • setRecipients(Message.RecipientType type, String addresses)—it’s used to set the stated recipient type to the provided addresses. The possible defined recipient types are “TO” (Message.RecipientType.TO), “CC” (Message.RecipientType.CC), and “BCC” (Message.RecipientType.BCC).
  • setSubject(String subject)—it’s used to set the email’s subject header field.
  • setText(String text)—it’s used to set the provided String as the email’s content, using MIME type of “text/plain”.
  • setContent(Object message, String contentType)—it’s used to set the email’s content using MIME type of “text/html”.

3. javax.mail.Address

The Address class is an abstract class that models the addresses (To and From addresses) in an email message; its subclasses support the actual implementations. Usually, its javax.mail.internet.InternetAddress subclass, which denotes an Internet email address, is commonly used.

4. javax.mail.Authenticator

The Authenticator class is an abstract class that is used to get authentication to access the mail server resources, often by requiring the user’s information. Its PasswordAuthentication subclass is commonly used. 

5. javax.mail.Transport

The Transport class is an abstract class that uses the SMTP protocol for submitting and transporting email messages.

How to send an email in Jakarta Mail

After going through the main classes of the Jakarta Mail API, let’s now see how to use them to send a simple email message via an SMTP server.

In short, here are the steps you will need to complete:

  • Configure the SMTP server details using the Java Properties object. For this tutorial, we will be using the SMTP server credentials provided to us by Mailtrap Email Sending, which is a reliable and hassle-free email API/SMTP service. But more on it a bit later.
  • Create a Session object by calling the getInstance() method. Then, pass the Mailtrap Email Sending SMTP server credentials to PasswordAuthentication. When creating the session object, you should always register the Authenticator with the Session
  • Create the email message to be sent. To do this, start by passing the created session object in the MimeMessage class constructor.
  • Set the From, To, and Subject fields for the email message.
  • Use the setText() method to set the content of the email message. 
  • Use the Transport object to send the email message.
  • Add Exceptions to retrieve the details of any possible errors when sending the message.

Getting the SMTP server credentials

Maitrap Email Sending SMTP credentials are very easy to find, and the process should take only a few steps.

Step #1 – Create a Mailtrap account and log in.

Step #2 – Add and verify a domain under Email Sending -> Sending Domains in your Mailtrap account, as shown in the video below:

Step #3 – Copy the SMTP server credentials from the API and SMTP page you will be taken to after domain verification and paste them in a convenient spot for when you will be writing your email-sending code.

Step #4 (optional) – Enable the Mailtrap Email Sending tracking settings so you can monitor your email performance. These settings will track your email opens as well as clicks.

The aggregated tracking data will be shown in the Stats tab of your Mailtrap account.

But if you want to see the data for each individual email, that will be shown in the Email Logs tab.

Step #5 (optional) – Enable unsubscribe settings by including either an unsubscribe link or an unsubscribe footer. The unsubscribe link is a lot more flexible as it can be placed anywhere in the email, but the setup process of the unsubscribe footer is quicker and easier. 

Do keep in mind that if you are sending marketing emails, having any kind of unsubscribe option is mandatory due to privacy laws in place.

Writing the code for sending the email

With SMTP server credentials retrieved and stored in a convenient place, you can now finally use them in your email sending code.

For users of Java and the Jakarta Mail API, that code should look like so:

package jakartaemail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import jakarta.mail.Authenticator;
public class JakartaEmail {
   public static void main(String[] args) {
      //provide recipient's email ID
      String to = "jakartato@example.com";
      //provide sender's email ID
      String from = "jakartafrom@example.com";
      //provide Mailtrap's username
      final String username = "api";
      //provide Mailtrap's password
      final String password = "********************************";
      //provide Mailtrap's host address
      String host = "send.smtp.mailtrap.io";
      //configure Mailtrap's SMTP server details
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.port", "587");
      //create the Session object
      Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(props, authenticator);

      try {
    //create a MimeMessage object
    Message message = new MimeMessage(session);
    //set From email field
    message.setFrom(new InternetAddress(from));
    //set To email field
    message.setRecipients(Message.RecipientType.TO,
               InternetAddress.parse(to));
    //set email subject field
    message.setSubject("Here comes Jakarta Mail!");
    //set the content of the email message
    message.setText("Just discovered that Jakarta Mail is fun and easy to use");
    //send the email message
    Transport.send(message);
    System.out.println("Email Message Sent Successfully");
      } catch (MessagingException e) {
         throw new RuntimeException(e);
      }
   }
}

Run the code and check the recipient inbox to see if the email arrived. 

Sending HTML email in Jakarta Mail

The process of sending an HTML email using the Jakarta Mail API is mostly the same as sending a simple email message. The only difference is that instead of the setText() method, we’ll be using the setContent() method to set content and we’ll specify “text/html” as the second argument thus indicating that the message has HTML content.

Here is the code to make it happen:

package jakartaemail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import jakarta.mail.Authenticator;
public class JakartaEmail {
   public static void main(String[] args) {
      //provide recipient's email ID
      String to = "jakartato@example.com";
      //provide sender's email ID
      String from = "jakartafrom@example.com";
      //provide Mailtrap's username
      final String username = "api";
      //provide Mailtrap's password
      final String password = "********************************";
      //provide Mailtrap's host address
      String host = "send.smtp.mailtrap.io";
      //configure Mailtrap's SMTP server details
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.port", "587");
      //create the Session object
      Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(props, authenticator);
      try {
    //create a MimeMessage object
    Message message = new MimeMessage(session);
    //set From email field
    message.setFrom(new InternetAddress(from));
    //set To email field
    message.setRecipients(Message.RecipientType.TO,
               InternetAddress.parse(to));
    //set email subject field
    message.setSubject("Here comes Jakarta Mail!");
    //set the content of the email message
    message.setContent("Just discovered that Jakarta Mail is fun and easy to use", "text/html");
    //send the email message
    Transport.send(message);
    System.out.println("Email Message Sent Successfully");
      } catch (MessagingException e) {
         throw new RuntimeException(e);
      }
   }
}

Send an Email with Attachments in Jakarta Mail

Apart from the previously mentioned steps, here are the additional steps involved in using the Jakarta Mail API for sending email attachments:

  • Create an instance of the MimeMultipart object that will be used for wrapping the MimeBodyPart body parts. A MimeMultipart acts like a container that holds multiple body parts, and it comes with methods for getting and setting its various subparts. 
  • Set the first part of the MimeMultipart object by passing the actual message to it. 
  • Set the second part of the MimeMultipart object by adding an attachment using a DataHandler object.
  • Include the MimeMultipart in the message to be sent. 

Here is what the steps look like when implemented in code:

package jakartaemail;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.activation.DataSource;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import jakarta.mail.Authenticator;
public class JakartaEmail {
   public static void main(String[] args) {
      //provide recipient's email ID
      String to = "jakartato@example.com";
      //provide sender's email ID
      String from = "jakartafrom@example.com";
      //provide Mailtrap's username
      final String username = "api";
      //provide Mailtrap's password
      final String password = "********************************";
      //provide Mailtrap's host address
      String host = "send.smtp.mailtrap.io";
      //configure Mailtrap's SMTP server details
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.port", "587");
      //create the Session object
       Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(props, authenticator);
      try {
    //create a MimeMessage object
    Message message = new MimeMessage(session);
    //set From email field
    message.setFrom(new InternetAddress(from));
    //set To email field
    message.setRecipients(Message.RecipientType.TO,
               InternetAddress.parse(to));
    //set email subject field
    message.setSubject("Here comes an attachment!");
   //create the message body part
    BodyPart messageBodyPart = new MimeBodyPart();
    //set the actual message
    messageBodyPart.setText("Please find the attachment sent using Jakarta Mail");
    //create an instance of multipart object
    Multipart multipart = new MimeMultipart();
    //set the first text message part
    multipart.addBodyPart(messageBodyPart);
    //set the second part, which is the attachment
    messageBodyPart = new MimeBodyPart();
    String filename = "C:\\Users\\OPIDI\\Desktop\\File 1\\gantt2.png";
    DataSource source = new FileDataSource(filename);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
    //send the entire message parts
    message.setContent(multipart);
    //send the email message
    Transport.send(message);
    System.out.println("Email Message Sent Successfully");
      } catch (MessagingException e) {
         throw new RuntimeException(e);
      }
   }
}

Debug Jakarta Mail

Debugging plays a critical role in the testing of email sending features. In Jakarta Mail, the debugging is pretty straightforward and you just have to set debug to true in the properties of your email code:

props.put("mail.debug", "true");

As a result, you will get a step-by-step description of how your code is executed. If any problem with sending your email appears, you will instantly understand what happened and at which stage.

Here is how our HTML message debug output looks:


DEBUG: Jakarta Mail version 2.0.1
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPTransport=jakarta.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=jakarta.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3Store=jakarta.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], com.sun.mail.smtp.SMTPSSLTransport=jakarta.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.imap.IMAPStore=jakarta.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3SSLStore=jakarta.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle]}
DEBUG: Providers Listed By Protocol: {imap=jakarta.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtp=jakarta.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], pop3=jakarta.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], imaps=jakarta.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], smtps=jakarta.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3s=jakarta.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=send.smtp.mailtrap.io, user=diana, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "send.smtp.mailtrap.io", port 587, isSSL false
220 mailtrap.io ESMTP
DEBUG SMTP: connected to host "send.smtp.mailtrap.io", port: 587
EHLO localhost
250-mailtrap.io
250-PIPELINING
250-SIZE 10485760
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
EHLO localhost
250-mailtrap.io
250-PIPELINING
250-SIZE 10485760
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: protocolConnect login, host=send.smtp.mailtrap.io, user=api, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<yourmail@example.com>>
250 2.1.0 Ok
RCPT TO:<johndoe@gmail.com>
250 2.1.5 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   johndoe@gmail.com
DATA
354 End data with <CR><LF>.<CR><LF>
Date: Mon, 16 Jan 2023 14:14:45 +0100 (CET)
From: yourmail@example.com
To: johndoe@gmail.com
Message-ID: <380936215.0.1673874885717@localhost>
Subject: Here comes Jakarta Mail!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Just discovered that Jakarta Mail is fun and easy to use
.
250 2.0.0 Ok: queued as c0a683fa-959f-11ed-b75e-0a58a9feac02
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 2.0.0 Bye
Email Message Sent Successfully

Alternative route: Sending using an email API

Sending emails using the Jakarta Mail API and SMTP server combination is quite common for Java projects, but it’s not the only route you can take.

Instead, a lot of developers opt for sending using an email API to automate the process and enjoy the features that often come with such solutions.

Mailtrap Email Sending, the sending solution we mentioned earlier in the article, besides an SMTP service also offers an email API that can reach customers inboxes just in time and give full control over email deliverability.

Now, we will demonstrate how to use this email API within your Java code.

Step #1 – Log into your Mailtrap account and go to Sending Domains -> API and SMTP page.

Step #2 – On the API and SMTP page, click on API and select Java from the list of languages in the Integrations section.

Step #3 – Copy the code you are provided with and paste it into your Java code:

OkHttpClient client = new OkHttpClient().newBuilder()
    .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"from\":{\"email\":\"mailtrap@mailtrap.club\",\"name\":\"Mailtrap Test\"},\"to\":[{\"email\":\"you@example.com\"}],\"subject\":\"You are awesome!\",\"text\":\"Congrats for sending test email with Mailtrap!\",\"category\":\"Integration Test\"}");
Request request = new Request.Builder()
    .url("https://send.api.mailtrap.io/api/send")
    .method("POST", body)
    .addHeader("Authorization", "Bearer <your api token>")
    .addHeader("Content-Type", "application/json")
    .build();
Response response = client.newCall(request).execute();

And you’re done! 

To learn more about Mailtrap Email Sending and how it can give you a stable working email infrastructure with high deliverability rates by design, be sure to check out the video below or visit the Mailtrap knowledgebase.

Testing your emails

An often-forgotten yet crucial step in the email sending process is testing your emails. Why? Well, have you ever received an email that’s not responsive, has broken links, and/or blurry images? Or an email that, in general, looks like no one previewed it before sending it?

If you are anything like us, you probably felt second-hand embarrassment for the sender. Yet, all the sender had to do was run some tests on their email to prevent that. 

Also, if a sender has any concerns about their emails being marked as spam or their domain being blacklisted, email testing with an equipped solution can help remove them.

We do the inspecting and debugging of our emails with Mailtrap Email Testing – a testing solution which belongs to the Mailtrap Email Delivery platform along with Mailtrap Email Sending we mentioned a few times throughout the article.

Mailtrap Email Testing captures all SMTP traffic from staging and dev environments, and so creates a safe environment for its users to test emails without spamming recipients. 

It also provides a range of features which include:

  • Multiple inboxes for different projects and stages of projects – find data, switch between tasks, and share testing results with colleagues/clients quickly.
  • Email preview – see how your email is rendered by a browser and find any issues related to responsiveness, images, links, variables, or content.
  • HTML analysis – scan your HTML/CSS to find problematic elements and see the support popular email clients have for your email code.
  • Spam analysis – get a spam report for your email content and a blacklist report for your sender domain/IP.
  • Tech info insight – see SMTP transaction info and original values of email headers
  • Email forwarding – send (manually or automatically) testing emails to whitelisted recipients.

So how do you start using this email testing solution in your project?

First, you have to log into your Mailtrap account

Then, under Email Testing -> Inboxes -> SMTP Settings – > Integrations, select the programming language you are using. This will generate a code snippet you need to copy and paste into your project code.

For Java-based projects, the following snippet is necessary:

package com.example.smtp;
import java.util.Properties;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;

public class SendEmail {
   public static void main(String[] args) {
      // Put recipient's address
      String to = "test@example.com";
      // Put sender's address
      String from = "from@example.com";
      final String username = "1a2b3c4d5e6f7g";//username generated by Mailtrap
      final String password = "1a2b3c4d5e6f7g";//password generated by Mailtrap
      // Paste host address from the SMTP settings tab in your Mailtrap Inbox
      String host = "smtp.mailtrap.io";
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");//it’s optional in Mailtrap
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.port", "2525");// use one of the options in the SMTP settings tab in your Mailtrap Inbox
      // Get the Session object.
      Session session = Session.getInstance(props,
         new jakarta.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
               return new PasswordAuthentication(username, password);
    }
         });
      try {
    // Create a default MimeMessage object.
    Message message = new MimeMessage(session);
    // Set From: header field
    message.setFrom(new InternetAddress(from));
    // Set To: header field
    message.setRecipients(Message.RecipientType.TO,
               InternetAddress.parse(to));
    // Set Subject: header field
    message.setSubject("My first message with JavaMail");
    // Put the content of your message
    message.setText("Hi there, this is my first message sent with JavaMail");
    // Send message
    Transport.send(message);
    System.out.println("Sent message successfully....");
      } catch (MessagingException e) {
         throw new RuntimeException(e);
      }
   }
}

Run the code, and the first test email should land in your Mailtrap Email Testing virtual inbox very shortly.

And that is it! You can now enjoy the above-mentioned features as well as benefits such as automation, saving time, and preserving domain reputation. Plus, you won’t have anything to be embarrassed or worried about when it comes to your emails :).

Wrapping up

And folks, that’s how you can use the Jakarta Mail API to send email messages in Java. We hope that this article will help you get started with the API and add powerful emailing capabilities to your Java applications. 

Do keep in mind that here we’ve just scratched the surface of what is possible with the Jakarta Mail Project. So, if you want to explore more usage examples, you can always check its expansive documentation.

Enjoy using Jakarta Mail!

Article by Alfrick Opidi Web developer & freelancer writer