View Source Swoosh.Adapters.Mandrill (Swoosh v1.8.1)
An adapter that sends email using the Mandrill API.
It supports both the send
and send-template
endpoint. In order to use the
latter you need to set template_name
in the provider_options
map on
Swoosh.Email
.
For reference: Mandrill API docs
example
Example
# config/config.exs
config :sample, Sample.Mailer,
adapter: Swoosh.Adapters.Mandrill,
api_key: "my-api-key"
# 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({"Rachel Chu", "rachel.chu@example.com"})
|> to({"Nick Young", "nick.young@example.com"})
|> to("astrid.leongteo@example.com")
|> reply_to("sk.starlight@example.com")
|> cc({"Goh Peik Lin", "goh.peiklin@example.com"})
|> cc("goh.wyemun@example.com")
|> bcc({"Eleanor Sung-Young", "eleanor.sungyoung@example.com"})
|> bcc("shang.suyi@example.com")
|> subject("Hello, People!")
|> html_body("<h1>Hello</h1>")
|> text_body("Hello")
|> put_provider_option(:global_merge_vars, [
%{"name" => "a", "content" => "b"},
%{"name" => "c", "content" => "d"}
])
|> put_provider_option(:merge_vars, [
%{"rcpt" => "a@example.com", "vars" => %{"name" => "a", "content" => "b"}},
%{"rcpt" => "b@example.com", "vars" => %{"name" => "b", "content" => "b"}},
])
|> put_provider_option(:merge_language, "mailchimp"),
|> put_provider_option(:metadata, %{"website" => "www.example.com"})
|> put_provider_option(:template_name, "welcome-user")
|> put_provider_option(:template_content, [%{"name" => "a", "content" => "b"}])
provider-options
Provider options
:global_merge_vars
(list[map]) - a list of maps of:name
and:content
global variables for all recipients:merge_language
(string) - merge tag language to use when evaluating merge tags, and possible values aremailchimp
orhandlebars
:merge_vars
(list[map]) - a list of maps of:rcpt
andvars
for each recipent, which will override:global_merge_vars
:metadata
(map) - a map of up to 10 fields for a user metadata:template_content
(list[map]) - a list of maps of:name
and:content
to be sent within a template:template_name
(string) - a name of slug of the template belongs to a user
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
.