Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

jakobkmar/SimpleKotlinMail

Repository files navigation

SimpleKotlinMail Logo

SimpleKotlinMail is a Kotlin Mail API, using coroutines and providing DSLs.

This project is not actively being worked on anymore, for an explanation and alternatives see #6 (comment) .

Features

  • build emails
  • send emails (using an external SMTP server)
  • receive and process emails
  • TLS support

To get started, visit the Documentation.

Examples

The purpose of the following code snippets is to provide an insight into the API. However, they are not suitable for learning the API, you should use the actual documentation for this.

Build

Build an email:

val email = emailBuilder {
    from("no-reply@example.com")
    to("foo@bar.com")

    withSubject("Important question")
    withPlainText("Hey, how are you doing?")
}

Send

Send that email:

suspend fun main() = email.send()

Server / Receive

Create a custom SMTPServer:

val smtpServer = smtpServer {
    mailListener {
        println(it.email.plainText)
    }
}.start(keepAlive = true)

Convert

// EML String -> Email
string.toEmail()
// MimeMessage -> Email
mimeMessage.email

HTML

Inside the email builder, you can easily access kotlinx.html:

emailBuilder {
    withHTML {
        div {
            h1 { +"Really important question!" }
            p { +"Hey, how are you doing?" }
        }
    }
}

And more

To learn more about SimpleKotlinMail, visit the Documentation.

Project information

This project uses SimpleJavaMail to deal with java MimeMessages in a more elegant way. On the server side, this projects depends on a fork of SubEthaSMTP.

If you use the documented functionality of SimpleKotlinMail, everything will make use of kotlinx.coroutines.