sslgmailelixirphoenix-framework

Phoenix / Elixir: Sending email via Gmail certificate error


I suspect it's some kind of certificate issue.

I'm running an Ubuntu server.

My Elixir / Phoenix code:

        case Mailer.deliver(email) do
          {:ok, _response} ->
            IO.puts("Email sent successfully.")
          {:error, reason} ->
            IO.puts("Failed to send email.")
            IO.puts("Reason: #{inspect(reason)}")
        end 

The error I get in production:

Failed to send email.
Reason: {:retries_exceeded, {:network_failure, ~c"142.250.141.109", {:error, {:options, :incompatible, [verify: :verify_peer, cacerts: :undefined]}}}}

And here's the relevant section of my config/prod.ex:

config :my_app, MyApp.Mailer,
  adapter: Swoosh.Adapters.SMTP,
  relay: "smtp.gmail.com",
  username: "myemail@gmail.com",
  password: "abcd 1234 abcd 1234",
  ssl: true,
  tls: :always,
  auth: :always,
  port: 465,
  retries: 1

I did try:

$ sudo apt-get install --reinstall ca-certificates

But no luck.

The complaint seems to be Elixir not being able to use Gmail's SSL certificate, is my understanding correct?


Solution

  • I did not try but, because of the cacerts: :undefined, it seems you miss a:

    cacerts: :public_key.cacerts_get(),
    

    See details in this bug report.