refrakt/mailer

Email sending abstraction.

Experimental. This module is lightly used and may change or move to its own package; see https://github.com/raskell-io/refrakt/issues/28.

Provides a simple interface for sending emails. In development, emails are logged to the console. In production, plug in an SMTP or API-based adapter.

Usage

import refrakt/mailer

let email = mailer.new()
  |> mailer.to("user@example.com")
  |> mailer.from("noreply@myapp.com")
  |> mailer.subject("Welcome!")
  |> mailer.text_body("Thanks for signing up.")
  |> mailer.html_body("<h1>Welcome!</h1>")

mailer.deliver(email, mailer.log_adapter())

Types

Email delivery adapter.

pub type Adapter =
  fn(Email) -> Result(Nil, String)

An email message.

pub type Email {
  Email(
    to: String,
    from: String,
    subject: String,
    text_body: String,
    html_body: String,
    reply_to: String,
  )
}

Constructors

  • Email(
      to: String,
      from: String,
      subject: String,
      text_body: String,
      html_body: String,
      reply_to: String,
    )

Values

pub fn deliver(
  email: Email,
  adapter: fn(Email) -> Result(Nil, String),
) -> Result(Nil, String)

Deliver an email using the given adapter.

pub fn from(email: Email, address: String) -> Email

Set the sender.

pub fn html_body(email: Email, body: String) -> Email

Set the HTML body.

pub fn log_adapter() -> fn(Email) -> Result(Nil, String)

Log adapter — prints emails to console. Use in development.

pub fn new() -> Email

Create a new empty email.

pub fn reply_to(email: Email, address: String) -> Email

Set the reply-to address.

pub fn subject(email: Email, subject: String) -> Email

Set the subject line.

pub fn text_body(email: Email, body: String) -> Email

Set the plain text body.

pub fn to(email: Email, address: String) -> Email

Set the recipient.

✨ Search Document