Mailroom is a Kotlin email composition and delivery library for server-side applications.
- Framework-agnostic core for any Kotlin server app
- Type-safe HTML DSL with kotlinx.html
- Pluggable adapters for SMTP, SES, Resend, local, and testing
- Optional Ktor plugin and mailbox preview UI
Add the dependencies:
dependencies {
implementation("dev.dela:mailroom-core:X.Y.Z")
implementation("dev.dela:mailroom-smtp:X.Y.Z")
}Configure, compose, and send:
val mailer = DefaultMailer(
SmtpAdapter(
SmtpConfig(
host = "smtp.example.com",
port = 587,
username = System.getenv("SMTP_USERNAME"),
password = System.getenv("SMTP_PASSWORD"),
useTLS = true,
),
),
)
val result = mailer.deliver(
email {
from("noreply@example.com", "My App")
to("user@example.com", "User Name")
subject("Welcome")
textBody("Thanks for signing up!")
},
)
when (result) {
is DeliveryResult.Success -> println("Sent: ${result.messageId}")
is DeliveryResult.Failure -> println("Failed: ${result.reason}")
}Documentation:
- mailroom-smtp — SMTP adapter built on Jakarta Mail (Gmail, Mailgun SMTP, etc.).
- mailroom-ses — Amazon SES adapter using the AWS SDK for Kotlin.
- mailroom-resend — Resend HTTP adapter.
- mailroom-local — In-memory adapter for local development with mailbox storage.
- mailroom-test — Test adapter with assertion DSL for verifying sent emails.
- Kotlin 2.1 or later
- JVM 17 or later
- Gradle 7.6.3 or later (built with Gradle 9.0)
- Coroutines support
- Ktor 3.2+ (only if using
mailroom-ktorandmailroom-preview)
MIT License - see LICENSE for details.
Mailroom is inspired by Swoosh, the excellent email library for Elixir.