Sendr

Package VersionHex Docs

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:

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:

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