All the Junk
My last blog post dealt with verifying user email addresses using confirmation emails and unique tokens. Even if you read the blog, in which I laid out the majority of the steps, you are bound to make mistakes setting it up. Now, imagine how many mistakes I made trying to set up this feature? In order to make sure the email function is working, you need to send, you know, emails. And when mistakes are made sending emails, you end up with an inbox full of them. I probably sent out over 100 emails to myself and group members before I got the feature to work the way I wanted it to. Good thing the Ruby community is so passionate about solving these problems because there is, you guessed it, a gem for that.
Here is an overview of what the letter-opener gem can do you for, taken from the github repository.
Preview email in the default browser instead of sending it. This means you do not need to set up email delivery in your development environment, and you no longer need to worry about accidentally sending a test email to someone else's address.
Not only will this gem allow you to render email templates in the browser, it is incredibly easy to implement. To implement the functionality of the gem, simply add the following to your gem file:
gem "letter_opener", :group => :development
and then in your
config/environments/development.rb add this configuration:
config.action_mailer.delivery_method = :letter_opener
and that's it.
Now, when you are testing your emails you will get something like this, that renders in your browser instead of filling your inbox with junk:
Not only will the text of the email be rendered, but links and attachments also become available in this environment. These messages will be stored locally in
tmp/letter-opener in case you wanted to check them after the window was closed.
Pretty cool right?
Please note that this is a Ruby on Rails implementation. However, the documentation for letter-opener does provide non-rails solutions and remote setups. Happy coding!