Create an email that only contains plain text.
import EmailAddress
import List.Nonempty
import Sendgrid
import String.Nonempty exposing (NonemptyString)
{-| An email to be sent to a recipient's email address.
-}
email : EmailAddress -> SendGrid.Email
email recipient =
SendGrid.textEmail
{ subject = NonemptyString 'S' "ubject"
, to = List.Nonempty.fromElement recipient
, content = NonemptyString 'H' "i!"
, nameOfSender = "test name"
, emailAddressOfSender = senderEmailAddress
}Create an email that contains html.
import EmailAddress
import List.Nonempty
import Sendgrid
import String.Nonempty exposing (NonemptyString)
{-| An email to be sent to a recipient's email address.
-}
email : (Result SendGrid.Error () -> msg) -> EmailAddress -> SendGrid.ApiKey -> Cmd msg
email msg recipient apiKey =
SendGrid.textEmail
{ subject = NonemptyString 'S' "ubject"
, to = List.Nonempty.fromElement recipient
, content = NonemptyString 'H' "i!"
, nameOfSender = "Sender Name"
, emailAddressOfSender = senderEmailAddress
}
|> SendGrid.sendEmail msg apiKeyNote 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.
Add a list of CC recipients.
Add a list of BCC recipients.
Attach files to the email. These will usually appear at the bottom of the email.
import Bytes exposing (Bytes)
import SendGrid
attachPngImage : String -> Bytes -> Email -> Email
attachPngImage name image email =
SendGrid.addAttachments
(Dict.fromList
[ ( name ++ ".png"
, { content = image
, mimeType = "image/png"
}
)
]
)
emailIf you want to include an image file within the body of your email, use Email.Html.inlinePngImg, Email.Html.inlineJpegImg, or Email.Html.inlineGifImg instead.
Send an email using the SendGrid API.
Send an email using the SendGrid API. This is the task version of sendEmail.
Possible error codes we might get back when trying to send an email. Some are just normal HTTP errors and others are specific to the SendGrid API.
The content of a generic SendGrid error.
The content of a 403 status code error.
A SendGrid API key. In order to send an email you must have one of these (see the readme for how to get one).