Java email client: send and receive emails and attachments in Java, Kotlin and more

MailSlurp Java SDK for sending and receive email and attachments on the JVM.

java email read

Create email addresses in Java using MailSlurp's official JVM SDK. Send and receive emails and attachments in Java, Kotlin, Groovy, Clojure and other JVM languages. MailSlurp lets you use real email in code and tests without need for SMTP mail servers.

Installation

You can install MailSlurp's email library from maven central.

Gradle build file

dependencies {
    implementation("com.mailslurp:mailslurp-client-java")
}

Maven pom file

<!-- place inside the <dependencies> block -->
<dependency>
  <groupId>com.mailslurp</groupId>
  <artifactId>mailslurp-client-java</artifactId>
  <version>LATEST</version>
  <type>pom</type>
</dependency>

Example usage

A basic usage of MailSlurp is to create a disposable test email account for testing. First configure your client with an API key that you can obtain from the MailSlurp dashboard.

Configure client

Import the MailSlurp package and configure the API key.

import com.mailslurp.apis.*;
import com.mailslurp.clients.*;
import com.mailslurp.models.*;

// create a MailSlurp client with your API_KEY
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setApiKey(YOUR_API_KEY);

Create an email account in Java

Use the inbox controller to create new inboxes:

// create an inbox using the inbox controller
InboxControllerApi inboxControllerApi = new InboxControllerApi(defaultClient);
Inbox inbox = inboxControllerApi.createInbox(null, null, null, null, null, null, null);

// verify inbox
assertEquals(inbox.getEmailAddress().contains("@mailslurp.com"), true);
assertNotNull(inbox.getId())

Get started