Skip to content

mailer/postmark

A ready-made mailer adapter for Postmark. Uses Erlang's built-in httpc — no extra dependencies required.

Functions

adapter

gleam
pub fn adapter(api_key api_key: String) -> mailer.Adapter

Return an adapter that delivers mail via the Postmark HTTP API. api_key is your Postmark server token.

Usage

gleam
import mistweaver/config
import mistweaver/mailer
import mistweaver/mailer/postmark

let adapter = postmark.adapter(api_key: config.require("POSTMARK_API_KEY"))

mailer.new()
|> mailer.from("no-reply@myapp.com")
|> mailer.to("user@example.com")
|> mailer.subject("Welcome!")
|> mailer.text_body("Thanks for signing up.")
|> mailer.html_body("<h1>Thanks for signing up.</h1>")
|> mailer.send(via: adapter)

Error handling

mailer.send returns Result(Nil, String). A non-2xx HTTP response from Postmark or a network error both produce Error(reason).

Building a custom HTTP adapter

mailer/postmark is a thin wrapper around mailer.adapter/1. You can do the same for any transactional email provider:

gleam
import mistweaver/mailer

let mailgun_adapter = mailer.adapter(fn(email) {
  // POST to api.mailgun.net with your credentials
})

Released under the Apache 2.0 License.