feat: allow text message

This commit is contained in:
2024-06-07 08:15:09 +02:00
parent 5b66cde5bc
commit 7ff96fabe1
4 changed files with 67 additions and 16 deletions

View File

@@ -36,18 +36,41 @@ defmodule Swoosh.Adapters.Mailinator do
Don't use this adapter for confidential information.
Use for tests only.
TODO: allow to choose from Text or HTML :prefer_html, :prefer_text
"""
"""
use Swoosh.Adapter, required_config: []
alias Swoosh.Email
alias Swoosh.Mailer
def deliver(%Email{} = email, _) do
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",