View Source Swoosh.Adapters.Mailjet (Swoosh v1.6.0)

An adapter that sends email using the Mailjet API.

For reference: Mailjet API docs


Mailjet adapter requires Plug to work properly.


# config/config.exs
config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.Mailjet,
  api_key: "my-api-key",
  secret: "my-secret-key"

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

Using with provider options

import Swoosh.Email

|> from({"Billi Wang", ""})
|> to({"Nai Nai", ""})
|> reply_to("")
|> cc({"Haiyan Wang", ""})
|> cc("")
|> bcc({"Hao Hao", ""})
|> bcc("")
|> subject("Hello, Nai Nai!")
|> html_body("<h1>Hello</h1>")
|> text_body("Hello")
|> put_provider_option(:template_id, 123)
|> put_provider_option(:template_error_deliver, true)
|> put_provider_option(:template_error_reporting, "")
|> put_provider_option(:variables, %{firstname: "lulu", lastname: "wang"})

Provider options

  • :template_id (integer) - TemplateID, unique template id of the template to be used as email content

  • :template_error_deliver (boolean) - TemplateErrorDeliver, send even if error in template if true, otherwise stop email delivery immediately upon error

  • :template_error_reporting (string | tuple | map) - TemplateErrorReporting, email address or a tuple of name and email address of a recipient to send a carbon copy upon error

  • :variables (map) - Variables, custom key-value variable for the email content

Link to this section Summary

Link to this section Functions

Callback implementation for Swoosh.Adapter.validate_config/1.

Callback implementation for Swoosh.Adapter.validate_dependency/0.