jorgemanrubia / mailgun_rails

Rails Action Mailer adapter for Mailgun
MIT License
210 stars 70 forks source link

Unexpected token at 'Mailgun Magnificent API' #77

Open btkramm opened 7 years ago

btkramm commented 7 years ago

Hi! I can send emails in my development environment but I can't in production. I'm getting the error: "765: unexpected token at 'Mailgun Magnificent API'"

rkapil12 commented 7 years ago

can you paste your request url, that might be the reason I guess, you migt have missed messages https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages

jeffb5000 commented 7 years ago

@rkapil12 Doesn't mailgun_rails already do that? In lib/mailgun_rails/client.rb the send_message function uses the mailgun_url which is an api_url of "https://api:#{api_key}@api.mailgun.net/v3/#{domain}" + "/messages"

Edit: In testing with postman against mailgun's api, I can get it to return 'Mailgun Magnificent API' if I leave off the /messages from the url. My understanding though is that mailgun_rails is adding /message to whatever url is entered as the domain in the config file.

thomas07vt commented 7 years ago

So I am not sure if this fixes your issue @btkramm , but I had the same error when I was using an incorrect domain. The documentation is a little ambiguous:

config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
  api_key: '<mailgun api key>',
  domain: '<mailgun domain>'
}

The "mailgun_domain" is the domain name that you register with mailgun. Let's say you registered mailgunrailsrocks.com and link it to your mailgun account. You will see something like this in your mailgun dashboard;

State Active
IP Address 127.0.0.1
SMTP Hostname smtp.mailgun.org
Default SMTP Loginpostmaster@mailgunrailsrocks.com
API Base URL https://api.mailgun.net/v3/mailgunrailsrocks.com
API Key key-abcxyz

you should NOT use https://api.mailgun.net/v3/mailgunrailsrocks.com/messages instead use the literal domain of mailgunrailsrocks.com in your config

so it will look like this:

config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
  api_key: 'key-abcxyz',
  domain: 'mailgunrailsrocks.com'
}
AlexAvlonitis commented 6 years ago

Had the same issue on production. Restarting my server solved it. My guess is caching issues, and instead of pinpointing what was stale (DNS, ENVs etc...), i just restarted the whole thing.

ricardovanlaarhoven commented 6 years ago

Ever found a solution?

nafaabout commented 5 years ago

Had the same issue. It turns out I forget to source the file where the api key and domain are exported.