trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

Mailer failure doesn't show a reasonable error message #74

Open StephenGrider opened 8 years ago

StephenGrider commented 8 years ago

Love this project, thanks so much! This may be out of scope of Addict; I'm adding it as an issue to help others who run into it.

Walking through the readme setup guide, I encountered an error when attempting to create an account on the /register route.

Error:

[error] #PID<0.976.0> running Workshop.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
        (elixir) lib/io.ex:346: IO.chardata_to_string(nil)
        (elixir) lib/path.ex:467: Path.join/2
        (elixir) lib/path.ex:449: Path.join/1
        lib/client.ex:44: Mailgun.Client.send_without_attachments/2
        lib/addict/mailers/mailgun.ex:11: Addict.Mailers.Mailgun.send_email/4
        lib/addict/interactors/register.ex:26: Addict.Interactors.Register.do_register/2
        lib/addict/controller.ex:16: Addict.AddictController.register/2
        lib/addict/controller.ex:1: Addict.AddictController.action/2
        lib/addict/controller.ex:1: Addict.AddictController.phoenix_controller_pipeline/2
        (workshop) lib/phoenix/router.ex:261: Workshop.Router.dispatch/2
        (workshop) web/router.ex:1: Workshop.Router.do_call/2
        (workshop) lib/workshop/endpoint.ex:1: Workshop.Endpoint.phoenix_pipeline/1
        (workshop) lib/plug/debugger.ex:93: Workshop.Endpoint."call (overridable 3)"/2
        (workshop) lib/phoenix/endpoint/render_errors.ex:34: Workshop.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

Steps to reproduce:

  1. Sign up for a mailgun account
  2. Do not active mailgun account (do not click the email verification link)
  3. Visit /register/ endpoint and create an account. Server throws a 500.
trenpixster commented 8 years ago

Thanks @StephenGrider! I'll make sure to have that addressed too 😄

kevin-DL commented 8 years ago

@StephenGrider Did you manage to get rid of the error?

Cheers.

trenpixster commented 8 years ago

@kevin-DL it seems what was missing was activating the mailgun account. Did you verify your e-mail address?

kevin-DL commented 8 years ago

@trenpixster : yes i have, in my case i have looked into it and it seems like it's not retrieving the configuration information. I will check my config.exs to see if i might have made a typo.

kevin-DL commented 8 years ago

That was it, some of my environment variables were not set properly.

Cheers.

It works on my local machine but not on heroku any ideas?

kevin-DL commented 8 years ago

It works properly on my local machine but not on heroku. Any ideas?

jaimeiniesta commented 8 years ago

I'm having this exact issue. I'm using the the sandbox API that Mailgun creates when you sign up as my DNS haven't yet been verified.

@kevin-DL what environment variables were missing in your case?

jaimeiniesta commented 8 years ago

I've tried it on a real, verified, active domain associated to a verified Mailgun account, but it keeps on failing exactly like in the issue description.

Devalo commented 8 years ago

I'm having the exact same problem. I've added mailgun through heroku and copied the API-url from the active sandbox domain into addict during installation. @kevin-DL also interested in those env variables you were missing :)

kevin-DL commented 8 years ago

In my case for my local env i was missing the env variable for the mailgun key was not set properly so returned nil when accessed

kevin-DL commented 8 years ago

It however does not work properly on heroku @Devalo for some reason. It was working at some point today but after an update it stopped working

jaimeiniesta commented 8 years ago

In my case it fails with Addict 0.2.4 and Mailgun client 0.1.2.

I've tried with the same Mailgun credentials in the example app that comes with Addict, and I get this error instead:

➔ mix phoenix.server
[info] Running ExampleApp.Endpoint with Cowboy using http on port 4000
[info] POST /register
[debug] Processing by Addict.AddictController.register/2
  Parameters: %{"email" => "jaimeiniesta@gmail.com", "name" => "Jaime", "password" => "[FILTERED]"}
  Pipelines: [:addict_routes]
[debug] INSERT INTO "users" ("inserted_at", "updated_at", "email", "encrypted_password", "name") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [{{2016, 5, 23}, {20, 8, 11, 0}}, {{2016, 5, 23}, {20, 8, 11, 0}}, "jaimeiniesta@gmail.com", "$pbkdf2-sha512$100000$l8htaZWlZXlhPWuocUhlwA$QgMIHTOWP5ebC8ojmP.ZZovmbPFI0xKHPz90hy4PEu1cHUuJ/BV52T7CoOEUKuA6ZGsfDcHa5AufU5H4/ZTqbA", "Jaime"] OK query=147.7ms queue=21.6ms
[debug] Unable to send e-mail to jaimeiniesta@gmail.com
:error
[debug] status: bad_fetch
[%{message: "Email: Unable to send e-mail (bad_fetch)"}]
[debug] reason:
[debug] no_scheme
[info] Sent 400 in 599ms
trenpixster commented 8 years ago

Really weird, everyone :| Can you try running mix deps.clean --all an try again?

jaimeiniesta commented 8 years ago

It works now! Thanks :) -- Tried it on the example app.

kevin-DL commented 8 years ago

Did not work for me. I will re-try my heroku install from scratch and see how it goes

joshuaswilcox commented 8 years ago

a mix deps.clean --all helped for me, not sure why though

dianjin commented 8 years ago

Yeah, same issue, and mix deps.clean --all worked! Thank you! 😄

garviand commented 7 years ago

Received error:

[debug] Unable to send e-mail to ga******@gmail.com [debug] status: bad_fetch [debug] reason: [debug] no_scheme

garviand commented 7 years ago

In case this happens to anybody else, the issue was my mailgun_domain in config :addict

it was mailgun_domain: sandboxXXXX.mailgun.org

had to change it to mailgun_domain: https://api.mailgun.net/v3/sandboxXXXX.mailgun.org

TB-Development commented 2 years ago

In case this happens to anybody else, the issue was my mailgun_domain in config :addict

it was mailgun_domain: sandboxXXXX.mailgun.org

had to change it to mailgun_domain: https://api.mailgun.net/v3/sandboxXXXX.mailgun.org

This sent me in the right direction.

The updated link was in the API section of my Sending domains in any of the pre-built programs.

In my case, they added a /messages to the end fo the domain...