Giter Club home page Giter Club logo

better_mailer_previews's Introduction

Better Mailer Previews — A lightweight Rails engine for improved email previews.

Better Mailer Previews is a Ruby on Rails gem that makes previewing all your ActionMailer email templates easier.

This gem/engine builds on top of native Rails mailer previews, with a few key enhancements like —

  • Shows all your previews live on the homepage
  • Easily resize individual mailers, for testing responsive layouts
  • Forward your previews to an email address (uses the default ActionMailer delivery method for your app).
  • Fully compatible with, and can live alongside, native Rails ActionMailer Previews

Here's a little demo I've put together ↓

Why did I build this?

I've used native Rails mailer previews extensively for building my ActionMailer email templates, but they're pretty barebones and lacking. In particular, I wanted a way to bulk-preview templates (rather than checking them one by one). I also wanted to be able to easily resize the email container for testing responsive layouts.

This gem is my idea brought to life, and I hope you'll find it useful!

Getting Started

  1. Add this line to the development group in your application's Gemfile:
group :development do
  ...
  gem "better_mailer_previews"
end
  1. And then execute:
$ bundle
  1. Finally, you need to mount this engine in your routes.rb file —
# routes.rb

Rails.application.routes.draw do
  mount BetterMailerPreviews::Engine, at: "/better_mailer_previews" if Rails.env.development?
  ...
end
  1. Run your Rails app, and visit localhost:3000/better_mailer_previews.
  2. Profit ✨

Sending email previews to an email address

This gem let's you send your email previews to an email address, using whatever default delivery method you have configured.

Better Mailer Previews sends it's emails using whichever config.action_mailer.delivery_method is defined for the environment. For example, if you're using Mailhog in development to test your emails, you might have a configuration like this —

# config/environments/development.rb
#
Rails.application.configure do
  ...
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {address: "127.0.0.1", port: 1025}
  config.action_mailer.raise_delivery_errors = false
end

In this case, Better Mailer Previews will send it's emails to Mailhog too (since it uses your existing configuration). If you want to send emails to a live inbox (like your personal email), you'd need to configure a live delivery method for the current environment.

How can I get previews to show up for my mailers?

This engine will display all the Actionmailer Previews defined in the host Ruby on Rails app. These are the mailer previews you've defined in test/mailers/previews, for use with native Actionmailer Previews.

For all the mailers you'd like to preview, you need to set up the corresponding ActionMailer::Preview class. Once you've done that, this engine will automatically pull them all in and let you preview them!

Other things to note

  • You need an internet connection for this to engine to work properly. This engine tries to load the TailwindCSS package via a CDN, to handle the app styling. Your browser will cache the package after you first download it though, which is handy.

More from me

If you like this gem, you'll probably like some of my other work (all Ruby on Rails stuff) —

If you want updates, you can also follow me on Twitter

License

The gem is available as open source under the terms of the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.