Create an email that only contains plain text.
import Email
import List.Nonempty
import String.Nonempty exposing (NonemptyString)
{-| An email to be sent to a recipient's email address.
-}
email : Email.Email -> SendGrid.Email
email recipient =
SendGrid.textEmail
{ subject = NonemptyString 'S' "ubject"
, to = List.Nonempty.fromElement recipient
, content = NonemptyString 'H' "i!"
, nameOfSender = "test name"
, emailAddressOfSender =
-- [email protected]
{ localPart = "this-can-be-anything"
, tags = []
, domain = "test"
, tld = [ "com" ]
}
}Create an email that contains html.
import Email
import Email.Html
import List.Nonempty
import String.Nonempty exposing (NonemptyString)
{-| An email to be sent to a recipient's email address.
-}
email : Email.Email -> SendGrid.Email
email recipient =
SendGrid.htmlEmail
{ subject = NonemptyString 'S' "ubject"
, to = List.Nonempty.fromElement recipient
, content =
Email.Html.div
[]
[ Email.Html.text "Hi!" ]
, nameOfSender = "test name"
, emailAddressOfSender =
-- [email protected]
{ localPart = "this-can-be-anything"
, tags = []
, domain = "test"
, tld = [ "com" ]
}
}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.
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).