defmodule Swoosh.Adapters.Mailinator do @moduledoc ~S""" An adapter that sends email to Mailinator.com service using the SMTP protocol. Underneath this adapter uses the [gen_smtp](https://github.com/gen-smtp/gen_smtp) library, add it to your mix.exs file. ## Example # mix.exs def deps do [ {:swoosh, "~> 1.3"}, {:gen_smtp, "~> 1.1"} ] end # config/config.exs config :sample, Sample.Mailer, adapter: Swoosh.Adapters.Mailinator # lib/sample/mailer.ex defmodule Sample.Mailer do use Swoosh.Mailer, otp_app: :sample end ## Note This adatper relay the email to the Mailinator.com SMTP server, no mater the internet domain of the recipient. This service provide no encryption in transit (SSL/TLS) nor authentication. This service provide public access to mailboxes. Don't use this adapter for confidential information. Use for tests only. """ use Swoosh.Adapter, required_config: [] alias Swoosh.Email alias Swoosh.Mailer def deliver(%Email{html_body: html, text_body: text} = email, _) when is_nil(html) do email |> delegate end def deliver(%Email{html_body: html, text_body: text} = email, _) when is_nil(text) do email |> delegate end def deliver(%Email{html_body: _, text_body: _} = email, _) do email |> Map.put(:text_body, nil) |> delegate end def deliver(%Email{text_body: _} = email, _) do email |> Map.put(:html_body, nil) |> delegate end def deliver(%Email{html_body: _} = email, _) do email |> Map.put(:text_body, nil) |> delegate end defp delegate(%Email{} = email) do email |> Mailer.deliver([ adapter: Swoosh.Adapters.SMTP, relay: "mail.mailinator.com", port: 25, tls: :never, auth: :never, retries: 1, no_mx_lookups: true ]) end end