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-cloud:1.0.0'
git slatekit/src/lib/kotlin/slatekit-cloud
docs Files
uses slatekit.results, slatekit.core,
license Apache 2.0
example Example_Files.kt

Back to top


This component uses the following other Slate Kit and/or third-party components.

Component Description
Results To model successes and failures with optional status codes
Utils Common utilities for both android + server

Back to top


    import slatekit.common.templates.Template
    import slatekit.common.templates.Templates

Back to top


    // Setup 1: Getting key 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("user://slatekit/conf/email.conf")

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

    // Setup 3a: Setup the email service ( basic ) with api key
    val emailService1 =  EmailServiceSendGrid(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("user://slatekit/templates/email_welcome.txt") ?: "" ),
         Template("email_pass", Uris.readText("user://slatekit/templates/email_password.txt") ?: "")
      subs = listOf(
        Pair("company.api" , { s -> "MyCompany"        }),
        Pair("app.api"     , { s -> "SlateKit.Sample"  })
    val emailService2 =  EmailServiceSendGrid(apiKey.key, apiKey.pass, apiKey.account, templates)

Back to top


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

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

    // Use case 3: Send message using one of the setup templates
    emailService2.sendUsingTemplate("email_welcome", "", "Welcome to", true,
                    Pair("greeting", "hello"),
                    Pair("user.api", "kishore"),
                    Pair("app.code", "ABC123")

Back to top