swoosh_mailinator/test/swoosh_mlntr.exs

62 lines
1.2 KiB
Elixir

Mix.install(
[
{:swoosh, "~> 1.7"},
{:gen_smtp, "~> 1.1"},
{:hackney, "~> 1.8"},
{:swoosh_mailinator, path: "."}, #app: false }
]
)
defmodule Main do
import Swoosh.Email
import Swoosh.Mailer
def test_both() do
prep()
end
def test_text_only() do
prep()
|> Map.delete(:html_body)
end
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
])
end
end
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()