MartinSStewart/send-grid/1.1.0

NOTE: the latest version is 4.1.4

SendGrid

Email

type alias Email a =
{ subject : Nonempty
, content : Content a
, to : Nonempty EmailAddress
, cc : List EmailAddress
, bcc : List EmailAddress
, nameOfSender : String
, emailAddressOfSender : EmailAddress
}
sendEmail : (Result Error () -> msg) -> ApiKey -> Email a -> Cmd msg

Send an email using the SendGrid API.

sendEmailTask : ApiKey -> Email a -> Task Error ()

Send an email using the SendGrid API. This is the task version of sendEmail.

type Error
= StatusCode400 (List ErrorMessage)
| StatusCode401 (List ErrorMessage)
| StatusCode403
{ errors : List ErrorMessage403
, id : Maybe String
}
| StatusCode413 (List ErrorMessage)
| UnknownError
{ statusCode : Int
, body : String
}
| NetworkError
| Timeout
| BadUrl String

Possible error codes we might get back when trying to send an email. Some are just normal HTTP errors, others are specific to the SendGrid API.

type alias ErrorMessage =
{ field : Maybe String
, message : String
, errorId : Maybe String
}

The content of a generic SendGrid error.

type alias ErrorMessage403 =
{ message : Maybe String
, field : Maybe String
, help : Maybe Value
}

The content of a 403 status code error.

API Key

In order to send email via SendGrid, you need an API key. To do this signup for a SendGrid account.

Then after you've logged in, click on the settings tab, then API Keys, and finally "Create API Key". You'll get to choose if the API key has Full Access, Restricted Access, or Billing Access. For this package it's best if you select restricted access and then set Mail Send to Full Access and leave everything else as No Access.

Once you've done this you'll be given an API key. Store it in a password manager or something for safe keeping. You are highly recommended to not hard code the API key into your source code!

type ApiKey

A SendGrid API key. In order to use the SendGrid API you must have one of these.

apiKey : String -> ApiKey

Create an API key from a raw string.

Email content

type Content a

The body of our email. This can either be plain text or html.

textContent : Nonempty -> Content a

Create a text body for an email.

htmlContent : Html a -> Content a

Create an html body for an email. Note that this function expects Html.String.Html as a parameter. To create those you'll need to run elm install zwilias/elm-html-string.