Skip to content

Kotlin Email Library

Official MailSlurp client for Kotlin. Create email accounts with real email addresses. Send and receive emails and attachments from Kotlin tests and code.

WARNING: Please use the Java version instead mailslurp-client-java as the Kotlin library cannot handle API methods that return generic lists at this stage.


The MailSlurp Kotlin package is hosted on Maven Central.




implementation 'com.mailslurp:mailslurp-client-kotlin:version'


MailSlurp for Kotlin provides API controllers that match the REST API for MailSlurp. Each controller must be provided with an API key. Create a free MailSlurp account to obtain an API key.

val apiKey: String = System.getenv("API_KEY")
val inboxController = InboxControllerApi(apiKey)


package com.mailslurp.examples

import com.mailslurp.apis.InboxControllerApi
import com.mailslurp.apis.WaitForControllerApi
import com.mailslurp.models.SendEmailOptions
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class MailSlurpKotlinTest {

  private val apiKey: String by lazy { System.getenv("API_KEY") }

  fun `can create inboxes`() {
    val inboxController = InboxControllerApi(apiKey)
    val inbox = inboxController.createInbox(null, null, null, null, null, null, null, null, null)
    assertTrue(inbox.emailAddress?.contains("@mailslurp") ?: false)

  fun `can send and receive email`() {
    // create inbox
    val inboxController = InboxControllerApi(apiKey)
    val waitForController = WaitForControllerApi(apiKey)
    val inbox = inboxController.createInbox(null, null, null, null, null, null, null, null, null)

    val testSubject = "test-subject"
    val confirmation = inboxController.sendEmailAndConfirm(
      inboxId =!!,
      sendEmailOptions = SendEmailOptions(
        to = listOf(inbox.emailAddress!!),
        subject = testSubject

    val email = waitForController.waitForLatestEmail(
      inboxId =!!,
      timeout = 60_000,
      unreadOnly = true
    assertTrue(email.subject == "test-subject")