2024-06-03 22:56:22 +00:00
|
|
|
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.
|
2024-06-07 06:15:09 +00:00
|
|
|
"""
|
2024-06-03 22:56:22 +00:00
|
|
|
|
|
|
|
use Swoosh.Adapter, required_config: []
|
|
|
|
|
|
|
|
alias Swoosh.Email
|
|
|
|
alias Swoosh.Mailer
|
|
|
|
|
2024-09-01 19:41:00 +00:00
|
|
|
def deliver(%Email{html_body: nil, text_body: _} = email, _) do
|
2024-06-07 06:15:09 +00:00
|
|
|
email |> delegate
|
|
|
|
end
|
|
|
|
|
2024-09-01 19:41:00 +00:00
|
|
|
def deliver(%Email{html_body: _, text_body: nil} = email, _) do
|
2024-06-07 06:15:09 +00:00
|
|
|
email |> delegate
|
|
|
|
end
|
|
|
|
|
|
|
|
def deliver(%Email{html_body: _, text_body: _} = email, _) do
|
2024-06-03 22:56:22 +00:00
|
|
|
email
|
|
|
|
|> Map.put(:text_body, nil)
|
2024-06-07 06:15:09 +00:00
|
|
|
|> 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
|
2024-06-03 22:56:22 +00:00
|
|
|
|> Mailer.deliver([
|
|
|
|
adapter: Swoosh.Adapters.SMTP,
|
|
|
|
relay: "mail.mailinator.com",
|
|
|
|
port: 25,
|
|
|
|
tls: :never,
|
|
|
|
auth: :never,
|
|
|
|
retries: 1,
|
|
|
|
no_mx_lookups: true
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|