Email

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.

Index

Section Component Description
1 Status Current status of this component
2 Install Installation instructions and references to sources
3 Requires Lists all the Slate Kit and third-party dependencies
4 Import Packages to import
5 Setup Set up of credentials, and configuration
6 Usage Usage and examples

Back to top



Status

This component is currently stable with a default implementation for AWS S3. However it is currently using the AWS 1.0 sdk that is synchonous. A future version will involve using AWS 2.0 sdk that is Async and incorporate Coroutines.
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 email1 =  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 email2 =  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 = email2.send("kishore@abc.com", "Welcome to MyApp.com", "showWelcome!", false)

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

    // Use case 3: Send message using one of the setup templates
    email2.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