ActionMailer not sending mail in development Rails 4
Solution 1
You should add
config.action_mailer.perform_deliveries = true
as by default this is on false, preventing mails to be sent from your development environment...
Solution 2
For anyone not using smtp, switching the delivery method to sendmail helped me in addition to explicitly setting deliveries to be performed:
config.action_mailer.delivery_method = :sendmail
Solution 3
If you're having issues sending email from console, you have to call the deliver method on your mail.
MyMailer.create_email.deliver
Solution 4
All of these answers are great, but there is another place where you can get burned, especially in the context of debugging.
In development.rb
make sure you set config.action_mailer.raise_delivery_errors = true
If your .deliver
method seems to be working without issue, but you never actually receive the email across the wire, your delivery method may be throwing an exception and rails is swallowing the error. This is very true if you simply have something as simple as a misconfigured credentials, or an aws access denied API error. Save ripping your hair out and make sure you have raise_delivery_errors
turned on. It wants to tell you something but can't.
Related videos on Youtube
Comments
-
Don P almost 2 years
Why is this mailer not sending any mail? (Or any ideas for debugging?)
In my_app/config/environments/development.rb I have this code:
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'my_app.com', user_name: ENV['GMAIL_USERNAME'], password: ENV['GMAIL_PASSWORD'], authentication: 'plain', enable_starttls_auto: true }
Then on my local computer in ~/.bash_profile I have this code:
export GMAIL_USERNAME='blah@my_app.com' export GMAIL_PASSWORD='***'
When I run
$ env
in my terminal, I see that both environment variables are correctly set.I have also restarted my rails server.
-
jb_314 over 10 yearsDoes it work as expected in
:test
or:file
delivery mode? That would isolate the problem to your smtp settings. -
Danny over 10 yearsMaybe a stupid question: did you change config.action_mailer.perform_deliveries = true, as by default this is on false, preventing mails to be sent from your development environment...
-
Don P over 10 yearsNot stupid at all @DannyVanHoof cause that was it! Thank you.
-
-
Jerome over 8 yearssendmail is quicker to configure on many servers. Particularly useful for development mode.
-
dtc almost 7 yearsthat statement doesn't make sense to me. you can make that call in the console.
-
Michael Brawn over 6 yearsSimply calling your method does not actually deliver mail while in rails console. You need to call the
deliver
method on the mail object that your Mailer method returns. -
dtc over 6 yearsmy mistake, i didnt know there was a create_email method but in the latest rails (and for a while now, i assumed),
MyMailer.deliver
should be enough. and you can do that either in console or the application -
Dog over 6 yearsi just wanted to add that for me in Rails 5, switching to :sendmail was the only thing that would work
-
Ryan Romanchuk over 5 yearsI recommend turning on
config.action_mailer.raise_delivery_errors = true
so delivery issues aren't being swallowed.