Quantcast
Viewing all articles
Browse latest Browse all 10

How to test emails in development mode in ruby on rails

Testing emails was always a pain for me and my designer friend. my designer friend keep asking me how can I test emails in development mode in ruby on rails without integrating sendgrid or critsend, so this post dedicated to him only.
I was always looking for a solution for the same, Specially after working on emaillist.io (A group emailing service.) and today I got one. MailCatcher.

Pretty easy to use and configure. Add in the gem file, add some code in config/development.rb and start the mailcatcher daemon. Lets do it one by one.
Add this in your gem file.

gem 'mailcatcher'

Run bundler and in your development configuration file config/development.rb, set the following Action Mailer settings:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'localhost', port: 1025 }

and start your rails app and mailcatcher daemon from terminal just by typing mailcatcher

mailcatcher
Starting MailCatcher
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080
*** MailCatcher runs as a daemon by default. Go to the web interface to quit.

Now open http://127.0.0.1:1080 in your browser and you can see a virtual inbox. Try triggering some email from your application and you will emails coming in your virtual inbox.
Another awesome feature of MailCatcher is that you can view both the HTML and plain text versions of emails, download attachments and also run some analysis of your email. I just loved it. I hope you will too. ;)

Make sure before going to production you test it in real scenario’s.

Sample Output

Image may be NSFW.
Clik here to view.
How to test emails in development mode in ruby on rails and run tests for various devices like iphone, ipad, blackberry etc.

How to test emails in development mode in ruby on rails and run tests for various devices like iphone, ipad, blackberry etc.

The post How to test emails in development mode in ruby on rails appeared first on Code Beer Startups.


Viewing all articles
Browse latest Browse all 10

Trending Articles