What is Letter Opener?
letter_opener
is a gem that allows you to preview sent emails in the browser instead of sending them to an inbox. It's useful for testing email functionality locally during development without actually sending the emails.
Why Use Letter Opener?
ActionMailer
for local testing.Installation & Setup
The letter_opener
gem is already included in your Gemfile
under the :development
group:
group :development do
gem 'letter_opener', '~> 1.10'
end
Run bundle install
to ensure the gem is installed.
Configure letter_opener in config/environments/development.rb
:
Rails.application.configure do
# Use letter_opener to view emails in the browser
config.action_mailer.delivery_method = :letter_opener
end
This configuration tells Rails to use the letter_opener
gem for email delivery in the development environment.
How Letter Opener Works
ActionMailer
, it will automatically open in your default browser.How to Test Email Sending
Trigger an Email:
Check the Email:
Troubleshooting Common Issues
letter_opener
is set as the delivery_method
in config/environments/development.rb
.