feat: allow text message
This commit is contained in:
parent
5b66cde5bc
commit
7ff96fabe1
10
README.md
10
README.md
|
@ -2,11 +2,13 @@
|
|||
|
||||
This project is an adapter for swoosh that relais any 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.
|
||||
Mailinator does not support multipart messages (they are processed as attachment which are ignored). So the adapter ensure that there is only htlm or text part and not both.
|
||||
|
||||
This service provide public access to mailboxes.
|
||||
The service provides no encryption in transit (SSL/TLS) nor authentication.
|
||||
|
||||
Don't use this adapter for confidential information.
|
||||
The service provides public access to mailboxes.
|
||||
|
||||
Don't use this adapter for private or confidential information.
|
||||
|
||||
Use for tests only.
|
||||
|
||||
|
@ -17,7 +19,7 @@ This module can be installed by adding `swoosh_mailinator` to your list of depen
|
|||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:swoosh_mailinator, "~> 0.1.0", git: "https://git.zoocoop.com/setop/swoosh_mailinator"}
|
||||
{:swoosh_mailinator, "~> 0.2.0", git: "https://git.zoocoop.com/setop/swoosh_mailinator"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
|
|
@ -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",
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -3,7 +3,7 @@ defmodule SwooshMailinator.MixProject do
|
|||
|
||||
def project do
|
||||
[
|
||||
version: "0.1.0",
|
||||
version: "0.2.0",
|
||||
deps: [
|
||||
{:swoosh, "~> 1.7"},
|
||||
]
|
||||
|
|
|
@ -11,20 +11,42 @@ defmodule Main do
|
|||
import Swoosh.Email
|
||||
import Swoosh.Mailer
|
||||
|
||||
def main do
|
||||
mess = """
|
||||
Compose, deliver and test your emails easily in Elixir.
|
||||
def test_both() do
|
||||
prep()
|
||||
end
|
||||
|
||||
Swoosh comes with many adapters, including SendGrid, Mandrill, Mailgun, Postmark and SMTP. See the full list of adapters below.
|
||||
def test_text_only() do
|
||||
prep()
|
||||
|> Map.delete(:html_body)
|
||||
end
|
||||
|
||||
The complete documentation for Swoosh is available online at HexDocs.
|
||||
"""
|
||||
def test_text_nil() do
|
||||
prep()
|
||||
|> text_body(nil)
|
||||
end
|
||||
|
||||
def test_html_only() do
|
||||
prep()
|
||||
|> Map.delete(:text_body)
|
||||
end
|
||||
|
||||
def test_html_nil() do
|
||||
prep()
|
||||
|> html_body(nil)
|
||||
end
|
||||
|
||||
def prep do
|
||||
mess = "mess"
|
||||
new()
|
||||
|> to("mlkjhg@kiujygtrfedc.com")
|
||||
|> from({"Who Knows", "who.knows@nonexisting.tld"})
|
||||
|> subject("Hello, Swoosh!")
|
||||
|> html_body("<h1>Hello World</h1><p>"<>mess<>"</p>")
|
||||
|> text_body(mess)
|
||||
end
|
||||
|
||||
def send(email) do
|
||||
email
|
||||
|> IO.inspect()
|
||||
|> deliver([
|
||||
adapter: Swoosh.Adapters.Mailinator
|
||||
|
@ -32,4 +54,8 @@ The complete documentation for Swoosh is available online at HexDocs.
|
|||
end
|
||||
end
|
||||
|
||||
Main.main() |> IO.inspect()
|
||||
Main.test_both() |> Main.send() |> IO.inspect()
|
||||
Main.test_text_only() |> Main.send() |> IO.inspect()
|
||||
Main.test_html_only() |> Main.send() |> IO.inspect()
|
||||
Main.test_text_nil() |> Main.send() |> IO.inspect()
|
||||
Main.test_html_nil() |> Main.send() |> IO.inspect()
|
||||
|
|
Loading…
Reference in New Issue