Repository: swoosh/swoosh (elixir)

Issue:
SMTP2GO: Reply-To field is ignored
Setting a reply-to field with reply_to/2 does not do anything. In fact, looks like the SMTP2GO adapter just doesn't process that field at all.

Pull request description:
Support reply_to in smtp2go
blocked by #850 

close #851 

Patch:
diff --git a/lib/swoosh/adapters/smtp2go.ex b/lib/swoosh/adapters/smtp2go.ex
index 1cf4904..f0b86d8 100644
--- a/lib/swoosh/adapters/smtp2go.ex
+++ b/lib/swoosh/adapters/smtp2go.ex
@@ -105,6 +105,7 @@ defmodule Swoosh.Adapters.SMTP2GO do
     |> prepare_template_data(email)
     |> prepare_template(email)
     |> prepare_custom_headers(email)
+    |> prepare_reply_to(email)
   end
 
   defp prepare_custom_headers(body, %{headers: headers}) do
@@ -115,6 +116,20 @@ defmodule Swoosh.Adapters.SMTP2GO do
     )
   end
 
+  defp prepare_reply_to(body, %{reply_to: nil}), do: body
+
+  defp prepare_reply_to(body, %{reply_to: reply_to}) do
+    reply_to_header_value =
+      reply_to
+      |> List.wrap()
+      |> prepare_recipients()
+      |> Enum.join(", ")
+
+    header = %{"header" => "Reply-To", "value" => reply_to_header_value}
+
+    Map.update(body, "custom_headers", [header], &[header | &1])
+  end
+
   defp prepare_attachments(body, %{attachments: []}), do: body
 
   defp prepare_attachments(body, %{attachments: attachments}) do


Test patch:
diff --git a/test/swoosh/adapters/smtp2go_test.exs b/test/swoosh/adapters/smtp2go_test.exs
index c5c84a6..92483c3 100644
--- a/test/swoosh/adapters/smtp2go_test.exs
+++ b/test/swoosh/adapters/smtp2go_test.exs
@@ -119,6 +119,98 @@ defmodule Swoosh.Adapters.SMTP2GOTest do
     assert SMTP2GO.deliver(email, config) == {:ok, %{id: "123456789"}}
   end
 
+  test "deliver/1 - valid email with singular reply_to",
+       %{
+         bypass: bypass,
+         config: config,
+         valid_email: email
+       } do
+    Bypass.expect(bypass, fn conn ->
+      conn = parse(conn)
+
+      body_params = %{
+        "api_key" => "api_key",
+        "custom_headers" => [%{"header" => "Reply-To", "value" => "reply-to@example.com"}],
+        "sender" => "sender@example.com",
+        "subject" => "Hello, world!",
+        "to" => ["receiver@example.com"]
+      }
+
+      assert body_params == conn.body_params
+      assert "/email/send" == conn.request_path
+      assert "POST" == conn.method
+
+      Plug.Conn.resp(conn, 200, @success_response)
+    end)
+
+    email = reply_to(email, "reply-to@example.com")
+
+    assert SMTP2GO.deliver(email, config) == {:ok, %{id: "123456789"}}
+  end
+
+  test "deliver/1 - valid email with multiple reply_to",
+       %{
+         bypass: bypass,
+         config: config,
+         valid_email: email
+       } do
+    Bypass.expect(bypass, fn conn ->
+      conn = parse(conn)
+
+      body_params = %{
+        "api_key" => "api_key",
+        "custom_headers" => [
+          %{"header" => "Reply-To", "value" => "reply-to1@example.com, reply-to2@example.com"}
+        ],
+        "sender" => "sender@example.com",
+        "subject" => "Hello, world!",
+        "to" => ["receiver@example.com"]
+      }
+
+      assert body_params == conn.body_params
+      assert "/email/send" == conn.request_path
+      assert "POST" == conn.method
+
+      Plug.Conn.resp(conn, 200, @success_response)
+    end)
+
+    email = reply_to(email, ["reply-to1@example.com", "reply-to2@example.com"])
+
+    assert SMTP2GO.deliver(email, config) == {:ok, %{id: "123456789"}}
+  end
+
+  test "deliver/1 - valid email with reply_to and custom headers",
+       %{
+         bypass: bypass,
+         config: config,
+         valid_email: email
+       } do
+    Bypass.expect(bypass, fn conn ->
+      conn = parse(conn)
+
+      body_params = %{
+        "api_key" => "api_key",
+        "custom_headers" => [
+          %{"header" => "Reply-To", "value" => "reply-to@example.com"},
+          %{"header" => "test", "value" => "value"}
+        ],
+        "sender" => "sender@example.com",
+        "subject" => "Hello, world!",
+        "to" => ["receiver@example.com"]
+      }
+
+      assert body_params == conn.body_params
+      assert "/email/send" == conn.request_path
+      assert "POST" == conn.method
+
+      Plug.Conn.resp(conn, 200, @success_response)
+    end)
+
+    email = email |> reply_to("reply-to@example.com") |> header("test", "value")
+
+    assert SMTP2GO.deliver(email, config) == {:ok, %{id: "123456789"}}
+  end
+
   test "deliver1/1 - 400", %{
     bypass: bypass,
     config: config,