Sendr #
A Gleam email library to unify sending emails.
Installation #
gleam add sendr
Usage #
import sendr
import sendr/message
import sendr/message/mailbox
import sendr/message/attachment
import sendr/backend
// Build a message
let msg =
message.new()
|> message.set_from(mailbox.new("Sender", "sender@example.com"))
|> message.set_to([mailbox.new("Recipient", "recipient@example.com")])
|> message.set_subject("Hello")
|> message.set_body_text("Hello, World!")
// Send the message
let assert Ok(req) = backend.request(msg, backend.config())
// Make the HTTP request with your HTTP client of choice:
// let resp = http_client.send(req)
// let result = backend.response(resp)
Backends #
Sendr uses a backend architecture so you can use different mail providers. Available backends:
-
sendr_lettermint - Send emails using lettermint.
-
sendr_scaleway - Send emails using Scaleway.
-
sendr_sweego - Send emails using sweego.
-
sendr_smtp - Send emails via SMTP.
Creating your own backend #
A backend is expected to have a request-function which takes a sendr/message.Message and transforms this to a http.Request, which can be passed to the backend using any HTTP-client.
In addition the backend should provide a response-function which takes in the returned http.Response and transforms it to a Result(String, SendrError(backend_error)) for further processing.
For examples look at the backends listed above.
Concepts #
Message #
A message contains all the standard email fields:
from- The senderreply_to- Where replies should be sentto- Primary recipientscc- Carbon copy recipientsbcc- Blind carbon copy recipientssubject- The email subject linebody- The message body (plain text and/or HTML)attachments- Files to attach
Mailbox #
A mailbox represents a recipient with a display name and email address. Both are trimmed of whitespace.
Attachment #
Attachments can be created from files or raw data. The content type is automatically detected from the filename extension.
Development #
gleam test # Run the tests
gleam run -m devutils/glinter -- --stats # Run the code style checks