The Email component is an abstraction of an Email Service with support for simple templates and a default implementation for sending emails using SendGrid.


This component is currently stable. Following limitations, current work, planned features apply.

Feature Status Description
Templates Upcoming Enhanced templating, possibly leveraging existing open-source templating systems.
Attachments Upcoming Support for adding attachments
HTML Upcoming Improved HTML support

Back to top


    repositories {
        // other repositories
        maven { url  "" }

    dependencies {
        // other dependencies ...

        compile 'com.slatekit:slatekit-notifications:1.0.0'

Back to top


Jar slatekit.notifications.jar
Package slatekit.notifications
Sources slatekit-notifications
Example Example_Email.kt
Requires See build.gradle for more info.

Back to top


Refer to Example_Email.kt for all imports.

    // Required

    // For Examples ( templated messages )
    import slatekit.common.templates.Template
    import slatekit.common.templates.TemplatePart
    import slatekit.common.templates.Templates

Back to top


    // Setup 1: Getting Api key/login info from config
    // Load the config file from slatekit directory in user_home directory
    // e.g. {user_home}/slatekit/conf/sms.conf
    // NOTE: It is safer/more secure to store config files there.
    val conf = Config.of("~/.slatekit/conf/email.conf")
    val apiKey1 = conf.apiLogin("email")

    // Setup 2: Get the api key either through conf or explicitly
    val apiKey2 = ApiLogin("17181234567", "ABC1234567", "password", "dev", "sendgrid-email")

    // Setup 3a: Setup the email service ( basic ) with api key
    val apiKey = apiKey1 ?: apiKey2
    val emailService1 = SendGrid(apiKey.key, apiKey.pass, apiKey.account)

    // Setup 3b: Setup the sms service with support for templates
    val templates =
                templates = listOf(
                        Template("email_welcome", Uris.readText("~/slatekit/templates/email_welcome.txt") ?: ""),
                        Template("email_pass", """
                         Hi @{},

                        Your code for @{} is @{app.code}.

                subs = listOf(
                        "" to { s: TemplatePart -> "My App" },
                        "app.from" to { s: TemplatePart -> "My App Team" },
                        "app.tagline" to { s:TemplatePart -> "My App tagline" }
    val emailService2 = SendGrid(apiKey.key, apiKey.pass, apiKey.account, templates)
    val email: EmailService = emailService2

Back to top


    // Sample email ( loaded from environment variable for test/example purposes )
    val toAddress = "SLATEKIT_EXAMPLE_EMAIL".env().orElse("")

    // Use case 1: Send a confirmation code to the U.S. to verify a users phone number.
    val result1 = email.send(toAddress, "Welcome to 1", "showWelcome!", false)

    // Use case 2: Send using a constructed message object
    email.sendSync(EmailMessage(toAddress, "Welcome to 2", "showWelcome!", false))

    // Use case 3: Send message using one of the setup templates
    val result2 = email.sendTemplate("email_welcome", toAddress, "Welcome to 3", true,
                    "app.confirmUrl" to "",
                    "" to "user1",
                    "" to "",
                    "app.code" to "ABC123"

Back to top