Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mailslurp/mailslurp-client-kotlin

Kotlin Email Library for MailSlurp
https://github.com/mailslurp/mailslurp-client-kotlin

Last synced: 19 days ago
JSON representation

Kotlin Email Library for MailSlurp

Awesome Lists containing this project

README

        

# 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](https://search.maven.org/artifact/com.mailslurp/mailslurp-client-java) as the Kotlin library cannot handle API methods that return generic lists at this stage.

## Quick links

- [Maven Central package](https://search.maven.org/artifact/com.mailslurp/mailslurp-client-kotlin)
- [Source code](https://github.com/mailslurp/mailslurp-client-kotlin)
- [Method Reference](https://docs.mailslurp.com/kotlin/docs/)
- [Documentation](https://docs.mailslurp.com/kotlin/docs/)

## Install

The MailSlurp Kotlin package is [hosted on Maven Central](https://search.maven.org/artifact/com.mailslurp/mailslurp-client-kotlin).

### Maven

```xml

com.mailslurp
mailslurp-client-kotlin
${version}

```

### Gradle

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

## Configure

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](https://app.mailslurp.com/sign-up/) to obtain an API key.

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

## Example

```kotlin
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

@RunWith(JUnit4::class)
class MailSlurpKotlinTest {

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

@Test
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)
}

@Test
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 = inbox.id!!,
sendEmailOptions = SendEmailOptions(
to = listOf(inbox.emailAddress!!),
subject = testSubject
)
)
assertEquals(confirmation.inboxId, inbox.id)

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