Swoosh.Adapters.Mailpit (Swoosh v1.26.0)

Copy Markdown View Source

An adapter that sends email to a self-hosted Mailpit server via its HTTP API.

For reference: Mailpit API docs

This adapter requires an API Client. Swoosh comes with Hackney, Finch and Req out of the box. See the installation section for details.

Example

# config/config.exs
config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.Mailpit,
  base_url: "https://mailpit.example.com",
  api_key: "YnJ...0Rw=="  # optional, for Basic Auth

# lib/sample/mailer.ex
defmodule Sample.Mailer do
  use Swoosh.Mailer, otp_app: :sample
end

Using with provider options

import Swoosh.Email

new()
|> from({"Raife Hastings", "raife@example.com"})
|> to({"Jed Haverford", "jed@example.com"})
|> reply_to("raife.hastings@example.com")
|> cc("eliza@example.com")
|> cc({"Jules Landry", "jules@example.com"})
|> bcc("james.reece@example.com")
|> bcc({"Ben Edwards", "ben@example.com"})
|> subject("Hello there")
|> html_body("<h1>Hello</h1>")
|> text_body("Hello")
|> put_provider_option(:tags, ["welcome", "transactional"])

Provider Options

Supported provider options are the following:

Inserted into request body

  • :tags (list of strings) - Mailpit tags

Summary

Functions

deliver(email, config \\ [])

Callback implementation for Swoosh.Adapter.deliver/2.

validate_config(config)

Callback implementation for Swoosh.Adapter.validate_config/1.

validate_dependency()

Callback implementation for Swoosh.Adapter.validate_dependency/0.