View Source Swoosh.Adapters.Mailgun (Swoosh v1.11.1)
An adapter that sends email using the Mailgun API.
For reference: Mailgun API docs
This adapter requires an API Client. Swoosh comes with Hackney and Finch out of the box. See the installation section for details.
dependency
Dependency
Mailgun adapter requires Plug
to work properly.
configuration-options
Configuration options
:api_key
- the API key used with Mailgun:domain
- the domain you will be sending emails from:base_url
- the url to use as the API endpoint. For EU domains, use https://api.eu.mailgun.net/v3
example
Example
# config/config.exs
config :sample, Sample.Mailer,
adapter: Swoosh.Adapters.Mailgun,
api_key: "my-api-key",
domain: "avengers.com"
# lib/sample/mailer.ex
defmodule Sample.Mailer do
use Swoosh.Mailer, otp_app: :sample
end
using-with-provider-options
Using with provider options
import Swoosh.Email
new()
|> from({"T Stark", "tony.stark@example.com"})
|> to({"Steve Rogers", "steve.rogers@example.com"})
|> to("wasp.avengers@example.com")
|> reply_to("office.avengers@example.com")
|> cc({"Bruce Banner", "hulk.smash@example.com"})
|> cc("thor.odinson@example.com")
|> bcc({"Clinton Francis Barton", "hawk.eye@example.com"})
|> bcc("beast.avengers@example.com")
|> subject("Hello, Avengers!")
|> html_body("<h1>Hello</h1>")
|> text_body("Hello")
|> put_provider_option(:custom_vars, %{"key" => "value"})
|> put_provider_option(:recipient_vars, %{"steve.rogers@example.com": %{var1: 123}, "juan.diaz@example.com": %{var1: 456}})
|> put_provider_option(:sending_options, %{dkim: "yes", tracking: "no"})
|> put_provider_option(:tags, ["worldwide-peace", "unity"])
|> put_provider_option(:template_name, "avengers-templates")
provider-options
Provider options
:custom_vars
(map) - used to translate tov:my-var
, nowh:X-Mailgun-Variables
, add custom data to email:recipient_vars
(map) -recipient-variables
, assign custom variable for each email recipient:sending_options
(map) -o:my-key
, all the sending options:tags
(list[string]) -o:tag
, was added in before:sending_options
, kept for backward compatibility, use:sending_options
instead:template_name
(string) -template
, name of template created at Mailgun
custom-headers
Custom headers
Headers added via Email.header/3
will be translated to (h:
) values that
Mailgun recognizes.
Link to this section Summary
Functions
Callback implementation for Swoosh.Adapter.validate_config/1
.
Callback implementation for Swoosh.Adapter.validate_dependency/0
.
Link to this section Functions
Callback implementation for Swoosh.Adapter.validate_config/1
.
Callback implementation for Swoosh.Adapter.validate_dependency/0
.