View Source Swoosh.Adapters.Mailtrap (Swoosh v1.16.5)

An adapter that sends email using the Mailtrap API.

For reference: Mailtrap 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.Mailtrap,
  api_key: "my-api-key"

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

Sandbox mode

For sandbox mode, use the following config:

# config/config.exs
config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.Mailtrap,
  api_key: "my-api-key",
  sandbox_inbox_id: "111111"

Using with provider options

import Swoosh.Email

new()
|> from({"Xu Shang-Chi", "xu.shangchi@example.com"})
|> to({"Katy", "katy@example.com"})
|> reply_to("xu.xialing@example.com")
|> cc("yingli@example.com")
|> cc({"Xu Wenwu", "xu.wenwu@example.com"})
|> bcc("yingnan@example.com")
|> bcc({"Jon Jon", "jonjon@example.com"})
|> subject("Hello, Ten Rings!")
|> html_body("<h1>Hello</h1>")
|> text_body("Hello")
|> put_provider_option(:custom_variables, %{
  my_var: %{my_message_id: 123},
  my_other_var: %{my_other_id: 1, stuff: 2}
})
|> put_provider_option(:category, "welcome")

Provider Options

Supported provider options are the following:

Inserted into request body

  • :category (string) - an email category

  • :custom_variables (map) - a map contains fields

Summary

Functions

Link to this function

deliver(email, config \\ [])

View Source

Callback implementation for Swoosh.Adapter.deliver/2.

Callback implementation for Swoosh.Adapter.validate_config/1.

Callback implementation for Swoosh.Adapter.validate_dependency/0.