百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

better_mailer_previews

> 后端框架
开源

Better Mailer Previews 是一个 Ruby on Rails 插件,可让您更轻松地预览 ActionMailer 电子邮件模板。

165 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Better Mailer Previews 是一个 Ruby on Rails 插件,可让您更轻松地预览 ActionMailer 电子邮件模板。

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
  • Supports namespaced mailers (think User::SignupMailer) as of v1.0.1

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:
ruby
group :development do
  ...
  gem "better_mailer_previews"
end
  1. And then execute:
bash
$ bundle
  1. Finally, you need to mount this engine in your routes.rb file —
ruby
# 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 —

ruby
# 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) —

  • RailsNotes, my Ruby on Rails blog
  • My Ruby on Rails Newsletter
  • RAILSG, a command builder for Rails generator commands
  • RailsNotes UI, a library of ActionMailer email templates and components

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.

Issues· 2 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rubyactionmaileremailruby-gemruby-on-rails

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架