Sending Emails with MailerSend and Java


Before you get started, make sure you have the following:

  • Java installed on your machine.
  • An active MailerSend account with an API key.

Set up the MailerSend Java SDK

You can use the MailerSend Java SDK by adding it to your project using a dependency management tool like Maven or Gradle.


Add the following to your pom.xml file:



Add the following to your build.gradle file:

implementation 'com.mailersend:java-sdk:1.0.0'

Set up the MailerSend API Key

To use the MailerSend Java SDK, you will need to set up your API key. You can find your API key in the MailerSend dashboard.

MailerSend ms = new MailerSend();

Send an Email

You are now ready to send an email using the MailerSend Java SDK. Here is an example of how to send an email:

Email email = new Email();
email.subject = "Hello from MailerSend!";
email.text = "This is a test email from the MailerSend Java SDK";
email.addRecipient("Recipient name", "");
email.setFrom("Sender name", "");

MailerSend ms = new MailerSend();

MailerSendResponse response = ms.emails().send(email);


In this example, we are sending a simple email with a plain text body.


You have successfully sent an email using MailerSend Java SDK. With the SDK, you can easily send emails using the MailerSend API in your Java applications.

What’s next?

Last Updated: