MartinSStewart/elm-email/1.0.2

Postmark

Sending emails

apiKey : String -> ApiKey

Create an API key from a raw string (see the readme for how to get one).

type ApiKey

A SendGrid API key. In order to send an email you must have one of these (see the readme for how to get one).

sendEmail : (Result SendEmailError () -> msg) -> ApiKey -> Email -> Cmd msg

Send an email

import EmailAddress exposing (EmailAddress)
import List.Nonempty
import Postmark


{-| An email to be sent to a recipient's email address.
-}
email : EmailAddress -> Cmd Msg
email recipient =
    Postmark.sendEmail
        SentEmail
        postmarkApiKey
        { from = { name = "ascii-collab", email = asciiCollabEmail }
        , to = List.Nonempty.fromElement { name = "", email = recipient }
        , subject = subject
        , body = Postmark.TextBody "Hello! Here's your login code 123123"
        , messageStream = Postmark.TransactionalEmail
        , attachments = Postmark.noAttachments
        }
(Result SendEmailsError () -> msg)
-> ApiKey
-> Nonempty Email
-> Cmd msg

Send multiple emails in a single API request. See more here https://postmarkapp.com/developer/user-guide/send-email-with-api/batch-emails

sendEmailTask : ApiKey -> Email -> Task SendEmailError ()

Send an email (but as a Task instead of a Cmd)

import EmailAddress exposing (EmailAddress)
import List.Nonempty exposing (Nonempty)
import Postmark
import Task exposing (Task)


{-| An email to be sent to a recipient's email address.
-}
email : EmailAddress -> Task Postmark.SendEmailError ()
email recipient =
    Postmark.sendEmailTask
        postmarkApiKey
        { from = { name = "ascii-collab", email = asciiCollabEmail }
        , to = List.Nonempty.fromElement { name = "", email = recipient }
        , subject = subject
        , body = Postmark.TextBody "Hello! Here's your login code: 123123"
        , messageStream = Postmark.TransactionalEmail
        , attachments = Postmark.noAttachments
        }
sendEmailsTask : ApiKey -> Nonempty Email -> Task SendEmailsError ()

Task version of sendEmails

type alias Email =
{ from :
{ name : String
, email : EmailAddress
}
, to :
Nonempty
{ name : String
, email : EmailAddress
}
, subject : NonemptyString
, body : EmailBody
, messageStream : MessageStream
, attachments : Attachments
}

Configuration for the email(s) you want to send.

{ from = { name = "ascii-collab", email = asciiCollabEmail }
, to = List.Nonempty.fromElement { name = "", email = recipient }
, subject = NonemptyString 'H' "ello!"
, body = Postmark.TextBody "Hello! Here's your login code 123123"
, messageStream = Postmark.TransactionalEmail
, attachments = Postmark.noAttachments
}
= HtmlBody Html
| TextBody String
| HtmlAndTextBody Html String
What kind of email content are you sending? Just plain text (TextBody), HTML (HtmlBody), or both (HtmlAndTextBody).
If you do send HTML, it's recommended to also send a plain text version for accessibility and it might reduce the odds of the email getting blocked by a spam filter.


Note that email clients are quite limited in what html features are supported!
To avoid accidentally using html that's unsupported by some email clients, the `Email.Html` and `Email.Html.Attributes` modules only define tags and attributes with universal support.
You can still use `Email.Html.node` and `Email.Html.Attributes.attribute` if you want something that might not be universally supported though.
= TransactionalEmail
| BroadcastEmail
| OtherMessageStream String

What type of email are you sending? TransactionalEmail is for high priority email intended for a single recipient (a login link for example). BroadcastEmail is for emails to be sent to many recipients (a product announcement or a terms of service change). OtherMessageStream is in case you have created additional message streams.

type alias PostmarkError_ =
{ errorCode : Int
, message : String
, to : List EmailAddress
}

Error message you can potentially get from Postmark

= UnknownError
{ statusCode : Int
, body : String
}
| PostmarkError PostmarkError_
| NetworkError
| Timeout
| BadUrl String

Possible errors we might get back when trying to send an email. Some are just normal HTTP errors and others are specific to the Postmark API.

= UnknownError_
{ statusCode : Int
, body : String
}
| PostmarkErrors (Nonempty PostmarkError_)
| NetworkError_
| Timeout_
| BadUrl_ String

Possible errors we might get back when trying to send multiple emails. Some are just normal HTTP errors and others are specific to the Postmark API.

Email attachments

A group of email attachments.

Note that the contents of each attachment has to be base64 encoded. This can be slow for large attachments so reuse the same Attachment for multiple emails if possible.

Don't include any attachments in the email.

Dict
String
{ content : Bytes
, mimeType : String
}

Create attachments to be shown at the bottom of an email. If you want to have inline image attachments, use Email.Html.inlineGifImg, Email.Html.inlineJpgImg, or Email.Html.inlinePngImg

Note that the contents of each attachment has to be base64 encoded. This can be slow for large attachments so you might want to reuse the same Attachment for multiple emails if possible.