App

Overview

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

Status

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



Install

    repositories {
        // other repositories
        maven { url  "http://dl.bintray.com/codehelixinc/slatekit" }
    }

    dependencies {
        // other dependencies ...

        compile 'com.slatekit:slatekit-cloud:1.0.0'
    }
package slatekit.cloud
jar slatekit.cloud.jar
git slatekit/src/lib/kotlin/slatekit-cloud
docs Files
uses slatekit.results, slatekit.core, slatekit.cloud
license Apache 2.0
example Example_Files.kt

Back to top



Requires

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



Imports

         
    import slatekit.notifications.email.EmailMessage
    import slatekit.notifications.email.EmailServiceSendGrid
    import slatekit.common.templates.Template
    import slatekit.common.templates.Templates
     

Back to top



Setup

        
    // 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.build(
      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



Usage

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

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

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

Back to top