I have a simple Ruby Sinatra app which allows users to request a new password - using Mailgun to trigger an email. It works perfectly well in development (localhost) but returns 'Internal Server Error' on Heroku. I'm still new to debugging Heroku so have looked at $ heroku logs but this doesn't appear to tell me anything of use. All Mailgun ENVs are correctly set under heroku:config.
Still a newbie to StackOverflow so please let me know if I can clarify my question further/provide more info....
App url - http://chitter-challenge.herokuapp.com/users/reset_password
Repo - https://github.com/timrobertson0122/chitter-challenge
Code snippet -
require 'rest-client'
class MailgunWrapper
def send_email_to user
api_key = ENV['MAILGUN_API_KEY']
api_url = "https://api:#{api_key}@api.mailgun.net/v3/sandboxf59a3be327d54fd79069be7d347b9af4.mailgun.org"
RestClient::Request.execute(
url: api_url + '/messages',
method: :post,
payload: {
from: 'postmaster@sandboxf59a3be327d54fd79069be7d347b9af4.mailgun.org',
to: user.email,
subject: 'This is subject',
text: 'This is text',
html: 'https://chitter-challenge.herokuapp.com/users/reset_password' + user.password_token,
multipart: true
},
headers: {
"h:X-My-Header" => 'www/mailgun-email-send'
},
verify_ssl: false
)
end
end
Gist of Heroku logs output - https://gist.github.com/timrobertson0122/fa79c18f66866ee180a3#file-gistfile1-txt
The only reason I can see for that to happen in your case is that your maligun domain 'sandboxf59a3be327d54fd79069be7d347b9af4'
might be incorrect. Have you checked your dashboard to see that the numbers actually match with your real domain. I've tried locally and getting the domain wrong is the only way I can see to get that error since the rest of the url is properly formatted.
Also you can try going here https://documentation.mailgun.com/quickstart-sending.html
which, if logged in, should give you an example of how to run a properly formatted post request with curl including your correct credentials. See if that works and if your params in the ruby code match what that says.