MailerSend
Interface for MailerSend, letting you easily send emails!
Installation
Section titled “Installation”Install kairo-mailersend-feature.
You don’t need to install the MailerSend SDK separately —
it’s included by default.
dependencies { implementation("com.highbeam.kairo:kairo-mailersend-feature")}First, add the Feature to your Server.
val features = listOf( MailersendFeature(config.mailersend),)We recommend using kairo-config to configure the Feature.
mailersend { apiToken = ${MAILERSEND_API_TOKEN} templates { "library-book-created" = "o65qngkm2kdlwr12" }}Now send an email!
val mailer: Mailer // Inject this.
val email = Email().apply { setFrom("Jeff Hudson", "jeff@highbeam.com") addRecipient("Gautam Gupta", "gautam@highbeam.com") setTemplateId(mailer.templates.getValue("library-book-created")) setSubject("New library book: ${libraryBook.title}") addPersonalization("library_book_title", libraryBook.title) addPersonalization("library_book_authors", libraryBook.authors.joinToString("\n")) addPersonalization("library_book_isbn", libraryBook.isbn)}mailer.use { emails().send(email) }Template mapping
Section titled “Template mapping”The templates config maps logical names to MailerSend template IDs.
Use mailer.templates.getValue("name") to look up a template ID at runtime.
This lets you swap template IDs across environments without changing code.
The use function
Section titled “The use function”mailer.use { ... } provides the underlying MailerSend SDK client as the receiver.
This is a suspending function that dispatches the SDK call off the calling coroutine.