Sending email 404 not found - nothing is happening, no debug messages

Edit: according to chatGTP the error is likely be on the mailgun connection, so therefore it’s the syntax I’m using, but not the mailgun creds. i.e Phoenix is calling the mailgun URL properly.

I’m trying to send an email but nothing happens: errors, logs, anything. Email is not received. I’ve confirmed that the Mailgun process does work with curl.

I can’t find a step-by-step tutorial on how to do this. So far I’ve cobbled together only this.

So I am trying it from iex

defmodule TurnStile.Mailer do
  use Swoosh.Mailer, otp_app: :turnStile


config :turnStile, TurnStile.Mailer,
      adapter: Swoosh.Adapters.Mailgun,
      domain: System.get_env("MAILGUN_DOMAIN"),
      api_key: System.get_env("MAILGUN_API_KEY")

config :swoosh, :api_client, Swoosh.ApiClient.Hackney

There is also some mailer stuff in runtime.exs, so the above also exist there too. I also don’t know what hackney is but I think it’s needed?

#notifier (take from swoosh docs)

defmodule TurnStile.Staff.EmployeeNotifier do
  import Swoosh.Email

  alias TurnStile.Mailer

  def welcome(user) do
    |> to({,})
    |> from({"Dr B Banner", "#{System.get_env("MAILGUN_DOMAIN")}/messages"})
    |> subject("Hello, Avengers!")
    |> html_body("<h1>Hello #{}</h1>")
    |> text_body("Hello #{}\n")

Not sure what goes in the from section. Above is one version of what I’ve tried.

In iex I try

email = TurnStile.Staff.EmployeeNotifier.welcome(%{name: "Tony Stark", email: ""})

I get:
{:error, {404, "404 page not found\n"}}

EDIT: in case it helps, this is how it works from curl

curl -s --user 'API_KEY' \ \
	-F from='Excited User <>' \
	-F \
	-F subject='Hello' \
	-F text='Testing some Mailgun awesomeness!'

The issue was with the domain and with the from field, and error was occuring in Swoosh. To many, these might be super obvious items, but maybe pointing them out will help other email novices. They were not obv to me,

  1. If full email URL is

  2. Then domain in the config is: domain: It is not the full URL.

  3. In the from field for the new() when making a new email (see welcome func above), this is also different from the full domain. It needs to include the mail part:

from({"Dr B Banner", ""})

Feedback to Swoosh: Better documentation would have made such obvious mistakes easier to correct. Also better error messages than just 404 not found. :slight_smile: