com.lightningkite.lightningserver.email.TestEmailClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-core Show documentation
Show all versions of server-core Show documentation
A set of tools to fill in/replace what Ktor is lacking in.
The newest version!
package com.lightningkite.lightningserver.email
/**
* A concrete implementation of EmailClient that will is similar to ConsoleEmailClient but with more options
* You can turn off the console printing
* It stores the last message sent
* You can set a lambda for getting send events
* This is useful for Unit Tests
*/
object TestEmailClient : EmailClient {
var onEmailSent: ((Email)->Unit)? = null
var lastEmailSent: Email? = null
private set
var printToConsole: Boolean = false
override suspend fun send(email: Email) {
lastEmailSent = email
onEmailSent?.invoke(email)
if (printToConsole) ConsoleEmailClient.send(email)
}
}