swoosh_mailinator/test/swoosh_mlntr.exs

62 lines
1.2 KiB
Elixir
Raw Normal View History

2024-06-03 22:56:22 +00:00
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
2024-06-07 06:15:09 +00:00
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
2024-06-03 22:56:22 +00:00
2024-06-07 06:15:09 +00:00
def test_html_only() do
prep()
|> Map.delete(:text_body)
end
def test_html_nil() do
prep()
|> html_body(nil)
end
2024-06-03 22:56:22 +00:00
2024-06-07 06:15:09 +00:00
def prep do
mess = "mess"
2024-06-03 22:56:22 +00:00
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)
2024-06-07 06:15:09 +00:00
end
def send(email) do
email
2024-06-03 22:56:22 +00:00
|> IO.inspect()
|> deliver([
adapter: Swoosh.Adapters.Mailinator
])
end
end
2024-06-07 06:15:09 +00:00
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()