Skip to content
Visual email testing
Branch: master
Clone or download
jeremy Merge pull request #77 from slavingia/master
Removed any default margin from body.
Latest commit 50831ad Sep 9, 2014

MailView -- Visual email testing

Preview plain text and html mail templates in your browser without redelivering it every time you make a change.

Rails 4.1

NOTE: MailView is part of Rails 4.1+. No need for the plugin anymore!


Add the gem to your Gemfile:

  gem 'mail_view', :git => ''
  # or
  gem "mail_view", "~> 2.0.4"

And run bundle install.


Since most emails do something interesting with database data, you'll need to write some scenarios to load messages with fake data. Its similar to writing mailer unit tests but you see a visual representation of the output instead.

  # app/mailers/mail_preview.rb or lib/mail_preview.rb
  class MailPreview < MailView
    # Pull data from existing fixtures
    def invitation
      account = Account.first
      inviter, invitee = account.users[0, 2]
      Notifier.invitation(inviter, invitee) 

    # Factory-like pattern
    def welcome
      user = User.create!
      mail = Notifier.welcome(user)

    # Stub-like
    def forgot_password
      user =, :name).new('', 'Jill Smith')
      mail = UserMailer.forgot_password(user)

Methods must return a Mail or TMail object. Using ActionMailer, call Notifier.create_action_name(args) to return a compatible TMail object. Now on ActionMailer 3.x, Notifier.action_name(args) will return a Mail object.


A mini router middleware is bundled for Rails 2.x support.

  # config/environments/development.rb
  config.middleware.use MailView::Mapper, [MailPreview]

For Rails³ you can map the app inline in your routes config.

  # config/routes.rb
  if Rails.env.development?
    mount MailPreview => 'mail_view'

Now just load up http://localhost:3000/mail_view.


Plain text view HTML view

You can’t perform that action at this time.