I’m having trouble sending emails from my Rails app hosted on Heroku. I’ve set up Mailgun as an add-on and verified my custom domain. The DNS records check out and I can send emails using the curl command provided by Mailgun.
However, when I try to send an email using ActionMailer, I get this error:
Net::SMTPFatalError (554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in domain settings.
My production.rb file looks like this:
EmailConfig.smtp_settings = {
port: ENV['MG_PORT'],
address: ENV['MG_SERVER'],
user_name: ENV['MG_LOGIN'],
password: ENV['MG_PASSWORD'],
domain: 'mysite.com',
authentication: :plain,
}
EmailConfig.delivery_method = :smtp
config.mailer_options = { host: 'mysite.com' }
I’ve double-checked all the environment variables and the ‘from’ address ([email protected]) in the logs. What could be causing this sandbox subdomain issue? Is there a step I’m missing or something that needs more time to update?
I encountered a similar issue when setting up Mailgun with Heroku. The key is to ensure you’re using the correct domain settings. Check your Mailgun dashboard and confirm you’ve switched from the sandbox to your custom domain. Also, verify that your DNS records (MX, TXT, and CNAME) are properly configured for your custom domain.
If everything looks correct, try clearing your Heroku config vars and resetting them. Sometimes cached values can cause problems. Use ‘heroku config:unset’ for each Mailgun-related variable, then set them again with the correct values from your Mailgun dashboard.
Lastly, remember that DNS changes can take up to 48 hours to propagate fully. If you’ve recently set up your custom domain, you might need to wait a bit longer for everything to sync up properly.
I’ve dealt with this exact issue before, and it can be frustrating. Here’s what worked for me:
First, check your Mailgun domain settings. Make sure you’ve switched from the sandbox to your custom domain. It’s easy to overlook this step.
Next, review your Heroku config vars. Sometimes they don’t update properly. I had to manually reset mine. Use ‘heroku config:set’ to update each Mailgun-related variable with the correct values from your Mailgun dashboard.
Also, double-check your ‘from’ email address in your mailer. It must match your verified custom domain.
If all else fails, try removing and re-adding the Mailgun add-on on Heroku. This fixed the issue for me when nothing else worked.
Remember, patience is key. DNS changes can take time to propagate fully. Give it a day or two if you’ve recently set everything up.
sounds like ur still using the sandbox domain instead of ur custom one. double check ur MG_SERVER env variable on heroku. it should be something like smtp.mailgun.org, not sandbox123.mailgun.org. also make sure ur ‘from’ address matches ur verified domain. hope this helps!