Bamboo email sent but console error

Hi All,

I hope you all are having a wonderful day/night.

I am using bamboo and mail jet for sending emails with my phoenix, absinthe back end app. The email is going out to the address fine but then the Bamboo.Mailer.deliver_now/4 completes in error. Here is the error I am getting…

21:52:16.372 [error] #PID<0.828.0> running AppWeb.Endpoint (connection #PID<0.827.0>, stream id 15) terminated
Server: (https)
Request: POST /api
** (exit) an exception was raised:
    ** (CaseClauseError) no case clause matching: %{body: "{ \"Sent\" : [{ \"Email\" : \"\", \"MessageID\" : 576460769204588905, \"MessageUUID\" : \"d028a093-732a-49ef-8d05-bbb577f1bf72\" }] }\n", headers: [{"date", "Tue, 28 Mar 2023 21:52:16 GMT"}, {"content-type", "application/json"}, {"content-length", "140"}], status_code: 200}
        (bamboo 2.3.0) lib/bamboo/mailer.ex:208: Bamboo.Mailer.deliver_now/4
        (app 0.1.0) lib/app_web/resolvers/accounts.ex:16: AppWeb.Resolvers.Accounts.signin/3
        (absinthe 1.7.1) lib/absinthe/resolution.ex:209:
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:232: Absinthe.Phase.Document.Execution.Resolution.reduce_resolution/1
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:187: Absinthe.Phase.Document.Execution.Resolution.do_resolve_field/3
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:172: Absinthe.Phase.Document.Execution.Resolution.do_resolve_fields/6
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:143: Absinthe.Phase.Document.Execution.Resolution.resolve_fields/4
        (absinthe 1.7.1) lib/absinthe/phase/document/execution/resolution.ex:88: Absinthe.Phase.Document.Execution.Resolution.walk_result/5

I tried wrapping the Bamboo.Mailer.deliver_now within a case statement but no luck. It keeps failing.

Appreciate your help.



  def deliver_now(adapter, email, config, opts) do
        case adapter.deliver(email, config) do
          {:ok, response} -> format_response(email, response, opts)
          {:error, _} = error -> error

And the result of adapter.deliver(email, config) which raises the CaseClauseError you’re seeing:

  body: "{ \"Sent\" : [{ \"Email\" : \"\", \"MessageID\" : 576460769204588905, \"MessageUUID\" : \"d028a093-732a-49ef-8d05-bbb577f1bf72\" }] }\n",
  headers: [{"date", "Tue, 28 Mar 2023 21:52:16 GMT"}, {"content-type", "application/json"}, {"content-length", "140"}],
  status_code: 200

The error is coming from a mismatch between what Bamboo expects from the adapter and what the adapter returns to Bamboo. And taking a look at the bamboo mailjet adapter repo, there’s this open issue and PR to address Breaking changes coming to Bamboo v2.0.0.

Probably not something you want to hear… But consider using a library that’s more stable and up-to date. That bamboo-mailjet wasn’t updated in few years time(!).

I recommend GitHub - swoosh/swoosh: Compose, deliver and test your emails easily in Elixir, it also has adapter for Mailjet. I use it with Postmark, it’s just plug and play and works as one would expect.

1 Like