mailgun_rails icon indicating copy to clipboard operation
mailgun_rails copied to clipboard

Unexpected token at 'Mailgun Magnificent API'

Open btkramm opened this issue 7 years ago • 6 comments

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

btkramm avatar Jun 24 '17 15:06 btkramm

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

rkapil12 avatar Aug 22 '17 08:08 rkapil12

@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.

jeffb5000 avatar Aug 27 '17 17:08 jeffb5000

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 [email protected]
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'
}

thomas07vt avatar Nov 09 '17 03:11 thomas07vt

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.

AlexAvlonitis avatar Nov 19 '17 14:11 AlexAvlonitis

Ever found a solution?

ricardovanlaarhoven avatar Feb 01 '18 11:02 ricardovanlaarhoven

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

nafaabout avatar Jan 29 '19 14:01 nafaabout