Mail Previews and Templates

Episode #58 by Teacher's Avatar David Kimura


Using ActionMailer::Preview preview email samples without sending them. Using Zurb's Foundation for Emails, learn how to use email templates with the Ink framework.
rails email tests framework 8:31


Foundation for Emails -
Foundation for Emails Templates Preview -
Foundation for Emails Templates Source -
Inky RB Gem -
Source -

UPDATE: They've changed domain names, but you can still access their site at


# Terminal
rails g mailer contact

# Gemfile
gem 'inky-rb', require: 'inky'
gem 'premailer-rails'

# Terminal
rails g inky:install

# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( foundation_emails.css )

# tests/mailers/previews/contact_mailer_preview.rb
# Preview all emails at http://localhost:3000/rails/mailers/contact_mailer
class ContactMailerPreview < ActionMailer::Preview
  # Preview this email at http://localhost:3000/rails/mailers/contact_mailer/feedback
  def feedback
    user = User.all.sample
    message = "Test message.", message)

# mailer.html.erb
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width" />

    <%= stylesheet_link_tag "foundation_emails" %>

    <table class="body" data-made-with-foundation>
        <td class="center" align="center" valign="top">
            <%= yield %>

# contact_mailer/feedback.html.inky
  <row class="header">
      <spacer size="16"></spacer>
      <h4 class="text-center">
        <%= @greeting %>
        <%= @user.first_name %>
        <%= @user.last_name %>,
      <spacer size="32"></spacer>
        <img src="">
      <spacer size="16"></spacer>
      <h1 class="text-center">Forgot Your Password?</h1>
      <spacer size="16"></spacer>
      <p class="text-center"><%= @message %></p>
      <button class="large expand" href="#">Reset Password</button>
      <p><small>You're getting this email because you've signed up for email updates. If you want to opt-out of future emails, <a href="#">unsubscribe here</a>.</small></p>
  <spacer size="16"></spacer>