mailglass is built for merge-blocking CI. This guide covers the built-in test assertions and the fake adapter for deterministic testing.

Prerequisites

Setup Test Config

# config/test.exs
config :mailglass,
  repo: Mailglass.TestRepo,
  adapter: Mailglass.Adapters.Fake

Use TestAssertions

defmodule MyApp.UserMailerTest do
  use ExUnit.Case, async: true
  import Mailglass.TestAssertions

  test "sends welcome email" do
    %{email: "bob@example.com"}
    |> MyApp.UserMailer.welcome()
    |> Mailglass.deliver()

    assert_mail_sent(to: "bob@example.com", subject: "Welcome")
  end
end

Inspection helpers

  • last_mail() — returns the last delivered message in the current process mailbox
  • wait_for_mail(params) — blocks until a matching mail arrives (useful for async/Oban testing)

End-to-End Example

import Mailglass.TestAssertions

%{email: "test@example.com"}
|> MyApp.UserMailer.welcome()
|> Mailglass.deliver()

assert_mail_sent(to: "test@example.com")
mail = last_mail()
assert mail.subject =~ "Welcome"