Compose, deliver and test your emails easily in Elixir
Alternatives To Swoosh
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Parse Server20,2701,140892 days ago220September 20, 2022402apache-2.0JavaScript
Parse Server for Node.js / Express
Bamboo1,835206374 months ago29June 11, 202138mitElixir
Testable, composable, and adapter based Elixir email library for devs that love piping.
Griddler1,361231102 years ago25May 09, 201827mitRuby
Simplify receiving email in Rails
Swoosh1,29369126 days ago90July 14, 202212mitElixir
Compose, deliver and test your emails easily in Elixir
7 years ago2December 15, 2015apache-2.0Java
An AutoCompleteTextView with builtin Adapter with the emails in the device.
Stampie28565a year ago24September 08, 20211mitPHP
Library for using online Email providers
Emailchecker2521462 months ago17December 27, 202119mitPHP
Disposable email detection library for PHP
Graphql Authentication235
12 years ago11May 29, 201862iscTypeScript
🔑 Makes it easy to do boring authentication stuff with GraphQL (login, password reset, ...)
Php Sparkpost19094182 years ago16March 08, 20212mitPHP
SparkPost client library for PHP
3 years ago2Java
android聊天的项目,包含了主流的功能。比如动态表情展示、语音、聊天表情、拍照、多图等。数据库也已经搭载好。服务器使用的是baidu push服务。还介绍了关于listview中item的两种不同处理方法
Alternatives To Swoosh
Select To Compare

Alternative Project Comparisons


hex.pm hex.pm hex.pm github.com

Compose, deliver and test your emails easily in Elixir.

We have applied the lessons learned from projects like Plug, Ecto and Phoenix in designing clean and composable APIs, with clear separation of concerns between modules. Swoosh comes with many adapters, including SendGrid, Mandrill, Mailgun, Postmark and SMTP. See the full list of adapters below.

The complete documentation for Swoosh is available online at HexDocs.


Elixir 1.11+ and Erlang OTP 23+

Getting started

# In your config/config.exs file
config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.Sendgrid,
  api_key: "SG.x.x"
# In your application code
defmodule Sample.Mailer do
  use Swoosh.Mailer, otp_app: :sample
defmodule Sample.UserEmail do
  import Swoosh.Email

  def welcome(user) do
    |> to({user.name, user.email})
    |> from({"Dr B Banner", "[email protected]"})
    |> subject("Hello, Avengers!")
    |> html_body("<h1>Hello #{user.name}</h1>")
    |> text_body("Hello #{user.name}\n")
# In an IEx session
email = Sample.UserEmail.welcome(%{name: "Tony Stark", email: "[email protected]"})
# Or in a Phoenix controller
defmodule Sample.UserController do
  use Phoenix.Controller
  alias Sample.UserEmail
  alias Sample.Mailer

  def create(conn, params) do
    user = create_user!(params)

    UserEmail.welcome(user) |> Mailer.deliver()

See Swoosh.Mailer for more configuration options.


  • Add swoosh to your list of dependencies in mix.exs:

    def deps do
      [{:swoosh, "~> 1.11"}]
  • (Optional-ish) Most adapters (non SMTP ones) use Swoosh.ApiClient to talk to the service provider. Swoosh comes with Swoosh.ApiClient.Hackney configured by default. If you want to use it, you just need to include Hackney as a dependency of your app.

    Swoosh also accepts Finch out-of-the-box. See Swoosh.ApiClient.Finch for details.

    If you need to integrate with another HTTP client, it's easy to define a new API client. Follow the Swoosh.ApiClient behaviour and configure Swoosh to use it:

    config :swoosh, :api_client, MyApp.ApiClient

    But if you don't need Swoosh.ApiClient, you can disable it by setting the value to false:

    config :swoosh, :api_client, false

    This is the case when you are using Swoosh.Adapters.Local, Swoosh.Adapters.Test and adapters that are SMTP based, that don't require an API client.

  • (Optional) If you are using Swoosh.Adapters.SMTP, Swoosh.Adapters.Sendmail or Swoosh.Adapters.AmazonSES, you also need to add gen_smtp to your dependencies:

    def deps do
        {:swoosh, "~> 1.6"},
        {:gen_smtp, "~> 1.0"}


Swoosh supports the most popular transactional email providers out of the box and also has an SMTP adapter. Below is the list of the adapters currently included:

Provider Swoosh adapter
SMTP Swoosh.Adapters.SMTP
SendGrid Swoosh.Adapters.Sendgrid
Sendinblue Swoosh.Adapters.Sendinblue
Sendmail Swoosh.Adapters.Sendmail
Mandrill Swoosh.Adapters.Mandrill
Mailgun Swoosh.Adapters.Mailgun
Mailjet Swoosh.Adapters.Mailjet
Postmark Swoosh.Adapters.Postmark
SparkPost Swoosh.Adapters.SparkPost
Amazon SES Swoosh.Adapters.AmazonSES
Amazon SES Swoosh.Adapters.ExAwsAmazonSES
Dyn Swoosh.Adapters.Dyn
SocketLabs Swoosh.Adapters.SocketLabs
Gmail Swoosh.Adapters.Gmail
MailPace Swoosh.Adapters.MailPace
SMTP2GO Swoosh.Adapters.SMTP2GO
ProtonBridge Swoosh.Adapters.ProtonBridge

Configure which adapter you want to use by updating your config/config.exs file:

config :sample, Sample.Mailer,
  adapter: Swoosh.Adapters.SMTP
  # adapter config (api keys, etc.)

Check the documentation of the adapter you want to use for more specific configurations and instructions.

Adding new adapters is super easy and we are definitely looking for contributions on that front. Get in touch if you want to help!


The Recipient Protocol enables you to easily make your structs compatible with Swoosh functions.

defmodule MyUser do
  @derive {Swoosh.Email.Recipient, name: :name, address: :email}
  defstruct [:name, :email, :other_props]

Now you can directly pass %MyUser{} to from, to, cc, bcc, etc. See Swoosh.Email.Recipient for more details.

Async Emails

Swoosh does not make any special arrangements for sending emails in a non-blocking manner. Opposite to some stacks, sending emails, talking to third party apps, etc in Elixir do not block or interfere with other requests, so you should resort to async emails only when necessary.

One simple way to deliver emails asynchronously is by leveraging Elixir's standard library. First add a Task supervisor to your application root, usually at lib/my_app/application.ex:

def start(_, _) do
  children = [
    # Before the endpoint
    {Task.Supervisor, name: MyApp.AsyncEmailSupervisor},

  Supervisor.start_link(children, strategy: :one_for_one)

Now, whenever you want to send an email:

Task.Supervisor.start_child(MyApp.AsyncEmailSupervisor, fn ->
  %{name: "Tony Stark", email: "[email protected]"}
  |> Sample.UserEmail.welcome()
  |> Sample.Mailer.deliver()

Please take a look at the official docs for Task and Task.Supervisor for further options.

One of the downsides of sending email asynchronously is that failures won't be reported to the user, who won't have an opportunity to try again immediately, and tasks by default do not retry on errors. Therefore, if the email must be delivered asynchronously, a safer solution would be to use a queue or job system. Elixir's ecosystem has many job queue libraries.

  • Oban is the current community favourite. It uses PostgreSQL for storage and coordination.
  • Exq uses Redis and is compatible with Resque / Sidekiq.

Phoenix integration

If you are looking to use Swoosh in your Phoenix project, make sure to check out the phoenix_swoosh project. It contains a set of functions that make it easy to render the text and HTML bodies using Phoenix views, templates and layouts.

Taking the example from above the "Getting Started" section, your code would look something like this:


    <title><%= @email.subject %></title>
    <%= @inner_content %>


  <h1>Welcome to Sample, <%= @username %>!</h1>


defmodule Sample.UserEmail do
  use Phoenix.Swoosh, view: Sample.EmailView, layout: {Sample.LayoutView, :email}

  def welcome(user) do
    |> to({user.name, user.email})
    |> from({"Dr B Banner", "[email protected]"})
    |> subject("Hello, Avengers!")
    |> render_body("welcome.html", %{username: user.username})

Feels familiar doesn't it? Head to the phoenix_swoosh repo for more details.


You can attach files to your email using the Swoosh.Email.attachment/2 function. Just give the path of your file as an argument and we will do the rest. It also works with a %Plug.Upload{} struct, or a %Swoosh.Attachment{} struct, which can be constructed using Swoosh.Attachment.new detailed here in the docs.

All built-in adapters have support for attachments.

|> to("[email protected]")
|> from({"Jarvis", "[email protected]"})
|> subject("Invoice May")
|> text_body("Here is the invoice for your superhero services in May.")
|> attachment("/Users/jarvis/invoice-peter-may.pdf")


In your config/test.exs file set your mailer's adapter to Swoosh.Adapters.Test so that you can use the assertions provided by Swoosh in Swoosh.TestAssertions module.

defmodule Sample.UserTest do
  use ExUnit.Case, async: true

  import Swoosh.TestAssertions

  test "send email on user signup" do
    # Assuming `create_user` creates a new user then sends out a
    # `Sample.UserEmail.welcome` email
    user = create_user(%{username: "ironman", email: "[email protected]"})
    assert_email_sent Sample.UserEmail.welcome(user)

Mailbox preview in the browser

Swoosh ships with a Plug that allows you to preview the emails in the local (in-memory) mailbox. It's particularly convenient in development when you want to check what your email will look like while testing the various flows of your application.

For email to reach this mailbox you will need to set your Mailer adapter to Swoosh.Adapters.Local:

# in config/dev.exs
config :sample, MyApp.Mailer,
  adapter: Swoosh.Adapters.Local

In your Phoenix project you can forward directly to the plug without spinning up a separate webserver, like this:

# in web/router.ex
if Mix.env == :dev do
  scope "/dev" do
    pipe_through [:browser]

    forward "/mailbox", Plug.Swoosh.MailboxPreview

You can also start a new server if your application does not depends on Phoenix:

# in config/dev.exs
# to run the preview server alongside your app
# which may not have a web interface already
config :swoosh, serve_mailbox: true
# in config/dev.exs
# to change the preview server port (4000 by default)
config :swoosh, serve_mailbox: true, preview_port: 4001

When using serve_mailbox: true make sure to have plug_cowboy as a dependency of your app.

{:plug_cowboy, ">= 1.0.0"}

And finally you can also use the following Mix task to start the mailbox preview server independently:

mix swoosh.mailbox.server

Note: the mailbox preview won't display emails being sent from outside its own node. So if you are testing using an IEx session, it's recommended to boot the application in the same session. iex -S mix phx.server or iex -S mix swoosh.mailbox.server will do the trick.

If you are curious, this is how it the mailbox preview looks like:


The preview is also available as a JSON endpoint.

curl http://localhost:4000/dev/mailbox/json


Swoosh starts a memory storage process for local adapter by default. Normally it does no harm being left around in production. However, if it is causing problems, or you don't like having it around, it can be disabled like so:

# config/prod.exs
config :swoosh, local: false


The following events are emitted:

  • [:swoosh, :deliver, :start]: occurs when Mailer.deliver/2 begins.
  • [:swoosh, :deliver, :stop]: occurs when Mailer.deliver/2 completes.
  • [:swoosh, :deliver, :exception]: occurs when Mailer.deliver/2 throws an exception.
  • [:swoosh, :deliver_many, :start]: occurs when Mailer.deliver_many/2 begins.
  • [:swoosh, :deliver_many, :stop]: occurs when Mailer.deliver_many/2 completes.
  • [:swoosh, :deliver_many, :exception]: occurs when Mailer.deliver_many/2 throws an exception.

View example in docs


Documentation is written into the library, you will find it in the source code, accessible from iex and of course, it all gets published to HexDocs.


We are grateful for any contributions. Before you submit an issue or a pull request, remember to:

  • Look at our Contributing guidelines
  • Not use the issue tracker for help or support requests (try StackOverflow, IRC or Slack instead)
  • Do a quick search in the issue tracker to make sure the issues hasn't been reported yet.
  • Look and follow the Code of Conduct. Be nice and have fun!

Running tests

Clone the repo and fetch its dependencies:

git clone https://github.com/swoosh/swoosh.git
cd swoosh
mix deps.get
mix test

Building docs

MIX_ENV=docs mix docs



Popular Email Projects
Popular Adapter Projects
Popular Messaging Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.