diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c6852..19c3de7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 1.2.1 - 2016-08-23 + +* Fix From/To headers passed to gen_smtp not to be formated that caused an error with some SMTP cloud providers like Amazon SES ([#31]) + +[#31]: https://github.com/fewlinesco/bamboo_smtp/pull/31 + ## 1.2.0 - 2016-08-02 * Fix order of name/email in `format_email` function ([#22]) diff --git a/README.md b/README.md index 7a621e2..47eb59f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The package can be installed as: ```elixir def deps do - [{:bamboo_smtp, "~> 1.2.0"}] + [{:bamboo_smtp, "~> 1.2.1"}] end ``` diff --git a/lib/bamboo/adapters/smtp_adapter.ex b/lib/bamboo/adapters/smtp_adapter.ex index 05d6fd1..8f48806 100644 --- a/lib/bamboo/adapters/smtp_adapter.ex +++ b/lib/bamboo/adapters/smtp_adapter.ex @@ -209,16 +209,17 @@ defmodule Bamboo.SMTPAdapter do |> raise_on_missing_configuration(config) end - defp format_email({nil, email}), do: email - defp format_email({name, email}), do: "#{name}<#{email}>" - defp format_email(emails) when is_list(emails) do - Enum.map(emails, &format_email/1) + defp format_email({nil, email}, _format), do: email + defp format_email({name, email}, true), do: "#{name} <#{email}>" + defp format_email({_name, email}, false), do: email + defp format_email(emails, format) when is_list(emails) do + Enum.map(emails, &format_email(&1, format)) end - defp format_email(email, type) do + defp format_email(email, type, format \\ true) do email |> Bamboo.Formatter.format_email_address(type) - |> format_email + |> format_email(format) end defp format_email_as_string(emails) when is_list(emails) do @@ -234,9 +235,9 @@ defmodule Bamboo.SMTPAdapter do |> format_email_as_string end - defp from(%Bamboo.Email{from: from}) do + defp from_without_format(%Bamboo.Email{from: from}) do from - |> format_email(:from) + |> format_email(:from, false) end defp put_default_configuration(config) do @@ -268,14 +269,14 @@ defmodule Bamboo.SMTPAdapter do """ end - defp to(%Bamboo.Email{} = email) do + defp to_without_format(%Bamboo.Email{} = email) do email |> Bamboo.Email.all_recipients - |> format_email(:to) + |> format_email(:to, false) end defp to_gen_smtp_message(%Bamboo.Email{} = email) do - {from(email), to(email), body(email)} + {from_without_format(email), to_without_format(email), body(email)} end defp to_gen_smtp_server_config(config) do diff --git a/mix.exs b/mix.exs index ec6dd6e..aa08acd 100644 --- a/mix.exs +++ b/mix.exs @@ -5,7 +5,7 @@ defmodule BambooSmtp.Mixfile do def project do [app: :bamboo_smtp, - version: "1.2.0", + version: "1.2.1", elixir: "~> 1.2", source_url: @project_url, homepage_url: @project_url, diff --git a/test/lib/bamboo/adapters/smtp_adapter_test.exs b/test/lib/bamboo/adapters/smtp_adapter_test.exs index 2c88a22..bf4a3a0 100644 --- a/test/lib/bamboo/adapters/smtp_adapter_test.exs +++ b/test/lib/bamboo/adapters/smtp_adapter_test.exs @@ -49,7 +49,7 @@ defmodule Bamboo.SMTPAdapterTest do defp check_email({from, _to, _raw}) do case from do - "Wrong User" -> + "wrong@user.com" -> {:error, :no_more_hosts, {:permanent_failure, "an-smtp-adddress", "554 Message rejected: Email address is not verified.\r\n"}} _ -> @@ -210,8 +210,8 @@ defmodule Bamboo.SMTPAdapterTest do raw_email, capture: :all_but_first) - assert format_email_as_string(bamboo_email.from) == from - assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to + assert format_email_as_string(bamboo_email.from, false) == from + assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n" assert String.contains?(raw_email, rfc822_subject) @@ -249,8 +249,8 @@ defmodule Bamboo.SMTPAdapterTest do raw_email, capture: :all_but_first) - assert format_email_as_string(bamboo_email.from) == from - assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to + assert format_email_as_string(bamboo_email.from, false) == from + assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n" assert String.contains?(raw_email, rfc822_subject) @@ -288,8 +288,8 @@ defmodule Bamboo.SMTPAdapterTest do raw_email, capture: :all_but_first) - assert format_email_as_string(bamboo_email.from) == from - assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to + assert format_email_as_string(bamboo_email.from, false) == from + assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n" assert String.contains?(raw_email, rfc822_subject) @@ -327,17 +327,19 @@ defmodule Bamboo.SMTPAdapterTest do assert String.contains?(raw_email, rfc822_subject) end + defp format_email(emails), do: format_email(emails, true) - defp format_email({name, email}), do: "#{name}<#{email}>" - defp format_email(emails) when is_list(emails) do - emails |> Enum.map(&format_email/1) + defp format_email({name, email}, true), do: "#{name} <#{email}>" + defp format_email({_name, email}, false), do: email + defp format_email(emails, format) when is_list(emails) do + emails |> Enum.map(&format_email_as_string(&1, format)) end defp format_email_as_string(emails) when is_list(emails) do emails |> format_email |> Enum.join(", ") end - defp format_email_as_string(email) do - format_email(email) + defp format_email_as_string(email, format \\ true) do + format_email(email, format) end defp assert_configuration(bamboo_config, gen_smtp_config) do