Skip to content

MailKTEmail for Kotlin, done carefully.

Coroutine-first IMAP and SMTP with hosted OAuth2 for Gmail and Outlook. Read, watch and send mail from your backend with explicit lifecycles, typed failures and no hidden persistence.

MailKT

A taste ​

kotlin
gmail.open(MailAddress("alice@gmail.com")).use { mailbox ->
    val inbox = checkNotNull(mailbox.folders.special(SpecialUse.INBOX)).path

    mailbox.messages.watchEnvelopes(inbox, MessageQuery(seen = false)).collect { watched ->
        val structure = mailbox.messages.structure(watched.envelope.location)
        structure.attachments.filter { it.isPdf }.forEach { part ->
            val pdf = mailbox.messages.download(part.ref, maxBytes = 10L * 1024 * 1024)
            store(pdf.content.toByteArray())
        }
        saveCheckpoint(watched.next) // only after your processing is durable
    }
}

Released under the MIT License.