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

An adapter that sends email using the SparkPost API.

For reference: SparkPost API docs


# config/config.exs
config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.SparkPost,
  api_key: "my-api-key",
  endpoint: ""
  # or "" for enterprise

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

Using with SparkPost templates

import Swoosh.Email

|> from("")
|> to("")
|> subject("Hello, Avengers!")
|> put_provider_option(:template_id, "my-first-email")
|> put_provider_option(:substitution_data, %{
  first_name: "Peter",
  last_name: "Parker"

Setting SparkPost transmission options

Full options can be found at SparkPost Transmissions API Docs

import Swoosh.Email

|> from("")
|> to("")
|> subject("Hello, Avengers!")
|> put_provider_option(:options, %{
  click_tracking: false,
  open_tracking: false,
  transactional: true,
  inline_css: true

Provider Options

  • :options (map) - customization on how the email is sent

  • :template_id (string) - id of the template to use

  • :substitution_data (map) - data passed to the template language in the content, and take precendence over the other data like :metadata

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.