I have Rails app on Heroku. It has a custom domain, and I've tried to set up email sending through Mailgun. I've installed Mailgun as an add-on through Heroku, and I've gone through the steps Mailgun gives to "verify" my custom domain. If I run Mailgun's "Check DNS Records Now" everything comes back green and the status is "Active." I can even send messages from my custom domain with the curl
call they provide. However, when I try to send an email from my Rails app using ActionMailer
I get: 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.
Why does it think I'm using a "Sandbox subdomain"? Here's what I have in environments/production.rb
:
# Mailgun
ActionMailer::Base.smtp_settings = {
port: ENV['MAILGUN_SMTP_PORT'],
address: ENV['MAILGUN_SMTP_SERVER'],
user_name: ENV['MAILGUN_SMTP_LOGIN'],
password: ENV['MAILGUN_SMTP_PASSWORD'],
domain: 'my-custom-domain.com',
authentication: :plain,
}
ActionMailer::Base.delivery_method = :smtp
# Devise recoverable
config.action_mailer.default_url_options = { host: 'my-custom-domain.com' }
For development I'm using Gmail so I know it's reading the right config file. And all the env vars are set correctly. The from is set correctly as well, I see it my logs ([email protected]) What did I miss? Is there something that could still be propagating even through the status is active?
Thanks!
So the issue turned out to be that when I verified my custom domain it created a second domain under my Heroku/Mailgun account. I still had the credentials from the xxx.mailgun.org (sandbox) domain in my Heroku env vars. Once I replaced them with the credentials from my custom domain everything worked. (Since Heroku set the first set of env vars I foolishly assumed the new set would get put in automatically.) Sigh...
Thanks for your help lyen.
To add on to lostphilosopher answer, I recently solved this MailGun custom domain issue myself.
Here's what worked for me:
Situation: After successfully adding a custom domain to Mailgun, my mail sending/receiving stopped working
Errors: After adding custom domain and verifying DNS with Mailgun, I received error messages such as:
Net::SMTPFatalError: 554 Sandbox subdomains are for test purposes only. Please add your own domain or add the address to authorized recipients in Account Settings.
Solution: Realize that Heroku does NOT automatically update configuration variables for you. You must manually update them with values for your new domain.
And yes I agree - MailGun docs are not the most thorough. Especially when it comes to testing your setup.
Did you add the recipients of your e-mail to "Authorized Recipients" list under https://mailgun.com/app/domains/sandbox_your_domain.mailgun.org
?
Be sure to add a real e-mail address which can receive e-mails.
This is because mailgun would send a confirmation e-mail asking if the owner of the e-mail address really wants to receive e-mails from mailgun.
MAILGUN_API_KEY
, MAILGUN_DOMAIN
, MAILGUN_SMTP_PASSWORD
, MAILGUN_SMTP_LOGIN
, MAILGUN_SMTP_SERVER
, MAILGUN_SMTP_PORT
with proper values.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With