Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the SMTP server response when sending an e-mail #122

Merged
merged 4 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/deps
/doc
/docs
.elixir_ls
erl_crash.dump
*.ez
4 changes: 2 additions & 2 deletions lib/bamboo/adapters/smtp_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ defmodule Bamboo.SMTPAdapter do
raise SMTPError, {reason, detail}
end

defp handle_response(_) do
:ok
defp handle_response(response) do
{:ok, response}
end

defp add_bcc(body, %Bamboo.Email{bcc: recipients}) do
Expand Down
44 changes: 22 additions & 22 deletions test/lib/bamboo/adapters/smtp_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Bamboo.SMTPAdapterTest do
def handle_call({:send_email, {email, config}}, _from, state) do
case check_validity(email, config) do
:ok ->
{:reply, :ok, [{email, config} | state]}
{:reply, "200 Ok 1234567890", [{email, config} | state]}

error ->
{:reply, error, state}
Expand Down Expand Up @@ -178,7 +178,7 @@ defmodule Bamboo.SMTPAdapterTest do

bamboo_email = new_email()
bamboo_config = SMTPAdapter.handle_config(configuration(config))
:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:relay] == "server"
Expand All @@ -189,7 +189,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("TLS", "if_available")

config = SMTPAdapter.handle_config(configuration(%{tls: {:system, "TLS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:tls] == :if_available
Expand All @@ -199,7 +199,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("TLS", "always")

config = SMTPAdapter.handle_config(configuration(%{tls: {:system, "TLS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:tls] == :always
Expand All @@ -209,7 +209,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("TLS", "never")

config = SMTPAdapter.handle_config(configuration(%{tls: {:system, "TLS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:tls] == :never
Expand All @@ -222,7 +222,7 @@ defmodule Bamboo.SMTPAdapterTest do
bamboo_email = new_email()
bamboo_config = configuration(%{username: {:system, "SMTP_USER"}, password: {:system, "SMTP_PASS"}})

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

Expand All @@ -234,7 +234,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("SSL", "true")

config = SMTPAdapter.handle_config(configuration(%{ssl: {:system, "SSL"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:ssl]
Expand All @@ -243,7 +243,7 @@ defmodule Bamboo.SMTPAdapterTest do
test "sets ssl false from System when specified" do
System.put_env("SSL", "false")
config = SMTPAdapter.handle_config(configuration(%{ssl: {:system, "SSL"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

refute gen_smtp_config[:ssl]
Expand All @@ -254,7 +254,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("RETRIES", "123")

config = SMTPAdapter.handle_config(configuration(%{retries: {:system, "RETRIES"}}))
:ok = SMTPAdapter.deliver(bamboo_email, config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert 123 == gen_smtp_config[:retries]
Expand All @@ -263,16 +263,16 @@ defmodule Bamboo.SMTPAdapterTest do
test "sets tls versions from System when specified" do
System.put_env("ALLOWED_TLS_VERSIONS", "tlsv1,tlsv1.2")
config = SMTPAdapter.handle_config(configuration(%{allowed_tls_versions: {:system, "ALLOWED_TLS_VERSIONS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert [:"tlsv1", :"tlsv1.2"] == gen_smtp_config[:tls_options][:versions]
assert [:tlsv1, :"tlsv1.2"] == gen_smtp_config[:tls_options][:versions]
end

test "sets no_mx_lookups false from System when specified" do
System.put_env("NO_MX_LOOKUPS", "false")
config = SMTPAdapter.handle_config(configuration(%{no_mx_lookups: {:system, "NO_MX_LOOKUPS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

refute gen_smtp_config[:no_mx_lookups]
Expand All @@ -281,7 +281,7 @@ defmodule Bamboo.SMTPAdapterTest do
test "sets no_mx_lookups true from System when specified" do
System.put_env("NO_MX_LOOKUPS", "true")
config = SMTPAdapter.handle_config(configuration(%{no_mx_lookups: {:system, "NO_MX_LOOKUPS"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:no_mx_lookups]
Expand Down Expand Up @@ -320,7 +320,7 @@ defmodule Bamboo.SMTPAdapterTest do
auth: :always
})

assert :ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
assert {:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)
end

test "deliver is successful when username and password configuration are not required" do
Expand All @@ -333,7 +333,7 @@ defmodule Bamboo.SMTPAdapterTest do
auth: :if_available
})

assert :ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
assert {:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)
end

test "deliver raises an exception when server configuration is wrong" do
Expand Down Expand Up @@ -368,7 +368,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("AUTH", "if_available")

config = SMTPAdapter.handle_config(configuration(%{auth: {:system, "AUTH"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:auth] == :if_available
Expand All @@ -378,7 +378,7 @@ defmodule Bamboo.SMTPAdapterTest do
System.put_env("AUTH", "always")

config = SMTPAdapter.handle_config(configuration(%{auth: {:system, "AUTH"}}))
:ok = SMTPAdapter.deliver(new_email(), config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(new_email(), config)
[{{_from, _to, _raw_email}, gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

assert gen_smtp_config[:auth] == :always
Expand All @@ -404,7 +404,7 @@ defmodule Bamboo.SMTPAdapterTest do
bamboo_email = new_email(text_body: nil)
bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

assert 1 = length(FakeGenSMTP.fetch_sent_emails)

Expand Down Expand Up @@ -443,7 +443,7 @@ defmodule Bamboo.SMTPAdapterTest do
bamboo_email = new_email(subject: nil)
bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

assert 1 = length(FakeGenSMTP.fetch_sent_emails)

Expand All @@ -459,7 +459,7 @@ defmodule Bamboo.SMTPAdapterTest do
bamboo_email = new_email(html_body: nil)
bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

assert 1 = length(FakeGenSMTP.fetch_sent_emails)

Expand Down Expand Up @@ -498,7 +498,7 @@ defmodule Bamboo.SMTPAdapterTest do
bamboo_email = new_email()
bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

assert 1 = length(FakeGenSMTP.fetch_sent_emails)

Expand Down Expand Up @@ -541,7 +541,7 @@ defmodule Bamboo.SMTPAdapterTest do

bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)
{:ok, "200 Ok 1234567890"} = SMTPAdapter.deliver(bamboo_email, bamboo_config)

[{{_from, _to, raw_email}, _gen_smtp_config}] = FakeGenSMTP.fetch_sent_emails

Expand Down