diff --git a/lib/bamboo/adapters/local_adapter.ex b/lib/bamboo/adapters/local_adapter.ex index e2358f0a..8d9f6291 100644 --- a/lib/bamboo/adapters/local_adapter.ex +++ b/lib/bamboo/adapters/local_adapter.ex @@ -32,9 +32,10 @@ defmodule Bamboo.LocalAdapter do @doc "Adds email to `Bamboo.SentEmail`, can automatically open it in new browser tab" def deliver(email, %{open_email_in_browser_url: open_email_in_browser_url}) do - %{private: %{local_adapter_id: local_adapter_id}} = SentEmail.push(email) - - {:ok, open_url_in_browser("#{open_email_in_browser_url}/#{local_adapter_id}")} + delivered_email = SentEmail.push(email) + %{private: %{local_adapter_id: local_adapter_id}} = delivered_email + open_url_in_browser("#{open_email_in_browser_url}/#{local_adapter_id}") + {:ok, delivered_email} end def deliver(email, _config) do @@ -45,6 +46,8 @@ defmodule Bamboo.LocalAdapter do def supports_attachments?, do: true + defp open_url_in_browser("test://" <> _), do: :opened + defp open_url_in_browser(url) when is_binary(url) do case :os.type() do {:unix, :darwin} -> System.cmd("open", [url]) diff --git a/test/lib/bamboo/adapters/local_adapter_test.exs b/test/lib/bamboo/adapters/local_adapter_test.exs index b89d5db1..6287d9e0 100644 --- a/test/lib/bamboo/adapters/local_adapter_test.exs +++ b/test/lib/bamboo/adapters/local_adapter_test.exs @@ -18,4 +18,11 @@ defmodule Bamboo.LocalAdapterTest do assert [%Bamboo.Email{subject: "This is my email"}] = SentEmail.all() end + + test "using open_email_in_browser_url doesn't raise an error" do + email = new_email(subject: "This is my email") + + assert {:ok, _response} = + email |> LocalAdapter.deliver(%{open_email_in_browser_url: "test://"}) + end end