Sendery
Sendery

Language SDKs

Kotlin

Use the Java SDK to send Sendery templates from Kotlin.

Install
implementation("co.sendery:sendery-java:0.1.4")
Source code

Requirements

Kotlin/JVM with Java 17+. Add the Java SDK dependency to your Gradle dependencies block.

Set up

Choose a published template and create a project API key. Store the key as SENDERY_API_KEY on your server.

Shell
export SENDERY_API_KEY="your_project_api_key"

Send an email

Replace your-template with your published template’s key and data with its variables.

Calls are blocking. In a coroutine, run the send inside withContext(Dispatchers.IO) using your application’s coroutine library.

Kotlin
import co.sendery.Sendery

fun main() {
    val sendery = Sendery(System.getenv("SENDERY_API_KEY"))
    val receipt = sendery.send("[email protected]", "your-template", mapOf(
        "name" to "Alex",
        "action_url" to "https://example.com/start"
    ))
    println(receipt.id())
}

Retrieve an email

Use the returned ID to check delivery status.

Kotlin
val message = sendery.get(receipt.id())
println(message.status())

Retry a send

Use retry(3) for up to three extra attempts after temporary failures. Keep the same idempotency key and email data on every attempt. API failures throw co.sendery.SenderyException.

Kotlin
val email = sendery.prepare("[email protected]", "your-template", mapOf(
    "name" to "Alex", "action_url" to "https://example.com/start"
), null, "your-idempotency-key")
val receipt = email.retry(3).send()

Send a specific version

Choose a published template version to keep sending it after newer versions are published. By default, Sendery uses the latest version.

Kotlin
val receipt = sendery.prepare("[email protected]", "your-template", mapOf(
    "name" to "Alex",
    "action_url" to "https://example.com/start"
)).version(3).send()

Attachments

Pass a list of Attachment objects with the filename, file bytes, and MIME type. The SDK handles base64 encoding.

Send up to 10 files totaling 5 MB. See the attachment reference for supported formats and limits.

Example
import co.sendery.Attachment
import java.nio.file.Files
import java.nio.file.Path

val file = Files.readAllBytes(Path.of("document.pdf"))

sendery.prepare(
    "[email protected]",
    "your-template",
    mapOf("name" to "Alex", "action_url" to "https://example.com/start"),
    null,
    "your-idempotency-key",
    listOf(Attachment("document.pdf", file, "application/pdf"))
).retry().send()