Wednesday, July 30, 2014

Rails deliver mail to local file

If you want to debug mail deliveries in development mode and want to see what exactly will be sent you can tell Rails to "deliver" emails to local folder file instead of sending them via sendmail or smtp.

# config/environments/development.rb
MyApp::Application.configure do
  # ...
  config.action_mailer.delivery_method = :file
  ActionMailer::Base.file_settings = { :location => Rails.root.join('tmp/mail') }
  # ...

In Rails 4.2 there is even better solution "Mail Previews" (... or show_previews) more info
But still if you want ho have the raw mail output, this is still valid solution.

keywords: Ruby on Rails 3, Rails 4, Rails 4.1, ActionMailer file