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!'