Kotlinmailer is a Kotlin Mail API, using coroutines and providing DSLs. It may be used in a Ktor Backend for verification mails.
This project is a hard fork from SimpleKotlinMail which is no more actively worked on.
Features
- build emails
- send emails (using an external SMTP server)
- TLS support
Documentation.
To get started, visit theSetup
Using Kotlinmailer requires Kotlin compiler 1.4.0
or higher due to the dependency on Kotlin Serialization
Gradle
Kotlin DSL:
repositories {
mavenCentral()
}
dependencies {
implementation("at.quickme.kotlinmailer:kotlinmailer-core:0.2.0")
// Optional for Kotlinx HTML DSL support
implementation("at.quickme.kotlinmailer:kotlinmailer-html:0.2.0")
}
Groovy DSL:
repositories {
mavenCentral()
}
dependencies {
implementation "at.quickme.kotlinmailer:kotlinmailer-core:0.2.0"
// Optional for Kotlinx HTML DSL support
implementation "at.quickme.kotlinmailer:kotlinmailer-html:0.2.0"
}
JVM Version
To be able to use the inline functions of the API, you have to configure the JVM version (if you have not done that already).
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = jvmVersionString // <- e.g. 11
}
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("[email protected]")
to("[email protected]")
withSubject("Important question")
withPlainText("Hey, how are you doing?")
}
Send
Send that email:
suspend fun main() = email.send()
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 Kotlinmailer, visit the Documentation.
Project information
This project uses SimpleJavaMail to deal with java MimeMessages in a more elegant way.
If you use the documented functionality of SimpleKotlinMail, everything will make use of kotlinx.coroutines.