Skip to content

Commit

Permalink
Merge pull request #60 from fewlinesco/feature/fix-error-empty-subject
Browse files Browse the repository at this point in the history
Fix email delivery issue when subject is empty
  • Loading branch information
kdisneur committed Jun 15, 2017
2 parents 93a5453 + 9ac4c14 commit 7a5c113
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/bamboo/adapters/smtp_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ defmodule Bamboo.SMTPAdapter do

defp add_smtp_line(body, content), do: body <> content <> "\r\n"

defp add_subject(body, %Bamboo.Email{subject: subject}) when is_nil(subject) do
add_smtp_header_line(body, :subject, "")
end
defp add_subject(body, %Bamboo.Email{subject: subject}) do
add_smtp_header_line(body, :subject, rfc822_encode(subject))
end
Expand Down
16 changes: 16 additions & 0 deletions test/lib/bamboo/adapters/smtp_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ defmodule Bamboo.SMTPAdapterTest do
assert_configuration bamboo_config, gen_smtp_config
end

test "email is sent when subject is not set" do
bamboo_email = new_email(subject: nil)
bamboo_config = configuration()

:ok = SMTPAdapter.deliver(bamboo_email, bamboo_config)

assert 1 = length(FakeGenSMTP.fetch_sent_emails)

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

rfc822_subject = "Subject: \r\n"
assert String.contains?(raw_email, rfc822_subject)

assert_configuration bamboo_config, gen_smtp_config
end

test "emails looks fine when only HTML body is set" do
bamboo_email = new_email(html_body: nil)
bamboo_config = configuration()
Expand Down

0 comments on commit 7a5c113

Please sign in to comment.