27

I want to test my registration process locally (development mode), how can I test how emails will be sent out and rendered etc?

I am not referring to a unit-test or integration test, but just while developing my app and going on the register page etc. I want it to send out the emails but to a file not using smtp.

Is this possible?

What options do I have?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

3 Answers3

52

This is configurable in the config/environments/*.rb files.

# output to tmp/mails directory
config.action_mailer.delivery_method = :file
# ... and to specify output location
# config.action_mailer.file_settings = { :location => Rails.root.join('tmp/mail') }

Detailed information can be found in the config section of Action Mailer Basics or on ActionMailer::Base API


Rails 4.2 :file delivery method source and Mail::FileDelivery source

Jake Berger
  • 5,237
  • 1
  • 28
  • 22
HakonB
  • 6,977
  • 1
  • 26
  • 27
8

LetterOpener makes it even simpler for you to preview the emails you just sent by opening the file in the browser automatically (in development environment of course).

lulalala
  • 17,572
  • 15
  • 110
  • 169
  • not working for me on Rails 4. I wish their Readme had more info or pointed towards a tutorial for rails 4. seems like a cool thing but the documentation for new users is not great – cwd Sep 25 '14 at 19:57
  • 2
    works for one-off testing that an email was sent, yet I might recommend [mailcatcher](https://github.com/sj26/mailcatcher#rvm) for long-term testing – Jake Berger Feb 04 '15 at 11:35
0

I realize you said you want to check emails in the context of manual testing, but it seems worth mentioning that these sorts of tests can be automated. email_spec is one gem i've used to do it.

fakeleft
  • 2,830
  • 2
  • 30
  • 32