A SendGrid API key. In order to send an email you must have one of these (see the readme for how to get one).
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
}Send multiple emails in a single API request. See more here https://postmarkapp.com/developer/user-guide/send-email-with-api/batch-emails
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
}Task version of sendEmails
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
}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.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.
Error message you can potentially get from Postmark
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.
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.
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.
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.
Create an API key from a raw string (see the readme for how to get one).