chrisdel101

chrisdel101

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
#mailer.ex

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

#conig.exs

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
    new()
    |> to({user.name, user.email})
    |> from({"Dr B Banner", "#{System.get_env("MAILGUN_DOMAIN")}/messages"})
    |> subject("Hello, Avengers!")
    |> html_body("<h1>Hello #{user.name}</h1>")
    |> text_body("Hello #{user.name}\n")
  end

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: "working@email.com"})
TurnStile.Mailer.deliver(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' \
	https://api.mailgun.net/v3/sandbox123456.mailgun.org/messages \
	-F from='Excited User <mailgun@sandbox123456.mailgun.org>' \
	-F to=working@email.com \
	-F subject='Hello' \
	-F text='Testing some Mailgun awesomeness!'

Marked As Solved

chrisdel101

chrisdel101

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 https://api.mailgun.net/v3/sandbox123456.mailgun.org

  2. Then domain in the config is: domain: sandbox123456.mailgun.org. 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", "mailgun@sandbox123456.mailgun.org"})

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:

Where Next?

Popular in Questions Top

fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement