Skip to content

Latest commit

 

History

History
147 lines (110 loc) · 2.73 KB

readme.md

File metadata and controls

147 lines (110 loc) · 2.73 KB

Emailer Effects Manager for Elm

An Effects Manager that enables a node Elm program to send Email. It supports the SMTP protocol as documented in nodemailer.

This is built on top of the Email library for node, nodemailer, and supports a subset of the library's functionality.

Install

You'll need Grove.

grove install panosoft/elm-emailer

Test program

The test program sends a text email. Use aBuild.sh or build.sh to build it and run it with node main command.

API

Commands

Send an email

Send an email using the supplied email config and options.

send : EmailConfig -> EmailOptions -> SendCompleteTagger msg -> Cmd msg
send config mailOptions tagger =

Usage

send config mailOptions SendComplete
  • SendComplete is your application's messages to handle the different result scenarios
  • config has fields used to configure the email transport.
  • mailOptions has email routing and content information.

EmailConfig

{-| Email credentials
-}
type alias Auth =
    { user : String
    , pass : String
    }


type alias EmailConfig =
    { host : String
    , port_ : Maybe Int
    , auth : Maybe Auth
    , secure : Bool
    , debug : Bool
    }

{-| Default EmailConfig options.  See nodemailer SMTP transport documentation.
-}
mtEmailConfig : EmailConfig
mtEmailConfig =
    { host = ""
    , port_ = Nothing
    , auth = Nothing
    , secure = True
    , debug = False
    }

Usage

config : EmailConfig
config =
    { mtEmailConfig
        | host = "localhost"
        , port_ = Just 465
        , auth = Just <| Auth "user" "password"
        , debug = True
    }

EmailOptions

{-| EmailOptions message can be plain text or html
-}
type EmailMessage
    = TextMessage String
    | HtmlMessage String


type alias EmailOptions =
    { from : String
    , to : String
    , subject : String
    , message : EmailMessage
    }

Usage

options : EmailOptions
options =
    { from = "[email protected]"
    , to = "[email protected]"
    , subject = "Testing elm-emailer"
    , message = TextMessage "This is a test message from elm-emailer"
    }

Subscriptions

There are no subscriptions.

Messages

SendCompleteTagger

Returns an elm Result indicating a successful email send or an error sending the email.

type alias SendCompleteTagger msg =
    ( Result String String ) -> msg

Usage

SendComplete (Ok message) ->
    let
        l =
            Debug.log "SendComplete" message
    in
    model ! []

SendComplete (Err error) ->
    let
        l =
            Debug.log "SendComplete Error" error
    in
        model ! []