Skip to content

Latest commit

 

History

History
67 lines (59 loc) · 1.73 KB

README.md

File metadata and controls

67 lines (59 loc) · 1.73 KB

Binom SMTP

Kotlin Library for send email using SMTP

Using

Gradle

You must add repository. See README

dependencies {
    api "pw.binom.io:smtp:<version>"
}

Example

val networkDispatcher = NetworkDispatcher()

val feature = async2 {
    // create tls smtp client
    val client = SMTPClient.tls(
        dispatcher = networkDispatcher,
        address = NetworkAddress.Immutable("smtp.yandex.ru", 465),
        keyManager = EmptyKeyManager,
        trustManager = TrustManager.TRUST_ALL,// trust to all domains
        fromEmail = "[email protected]",
        login = "[email protected]",
        password = "test_password"
    )

    // simple message with html body
    client.multipart(
        from = "[email protected]",
        fromAlias = "Journal",
        to = "[email protected]",
        toAlias = "Anton",
        subject = "Test Message"
    ) {
        it.appendText("text/html").use {
            it.append("<html><s>Second email! Without attachment!</s>")
        }
    }
    
    // message with html body and attachment
    client.multipart(
        from = "[email protected]",
        fromAlias = "Test Binom Client",
        to = "[email protected]",
        toAlias = "Anton",
        subject = "Test Message"
    ) {
        it.appendText("text/html").use {
            it.append("<html>Hello from <b>Kotln</b><br><br><i>This</i> is an example HTML with attachment!<br><s>Зачёрктнутый</s>")
        }

        it.attach(name = "my_text.txt").use {
            it.write(ByteBuffer.wrap("MyData in TXT file".encodeToByteArray()))
        }
    }

    // close tls smtp client
    client.asyncClose()
}

while (!feature.isDone) {
    networkDispatcher.select()
}
feature.joinAndGetOrThrow()