Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

maily

> 后端框架
Open source

Rails Engine to preview emails in the browser

707 stars0 likes2 views
WebsiteGitHub

About

Rails Engine to preview emails in the browser

Maily is a Rails Engine to manage, test and navigate through all your email templates of your app, being able to preview them directly in your browser.

Maily automatically picks up all your emails and make them accessible from a kind of dashboard.

Features:

  • Mountable engine
  • Visual preview in the browser (attachments as well)
  • Template edition (only in development)
  • Email delivery
  • Easy way (aka Hooks) to define and customize data for emails
  • Email versions
  • Flexible authorization system
  • Minimalistic and clean interface
  • Generator to handle a comfortable installation

Installation

Add this line to your Gemfile and then run bundle install:

ruby
gem 'maily'

Run generator:

> rails g maily:install

This generator runs some tasks for you:

  • Mounts the engine (to /maily by default) in your routes
  • Adds an initializer (into config/initializers/maily.rb) to customize some settings
  • Adds a file (into lib/maily_hooks.rb) to define hooks

Initialization and configuration

You should use the setup method to configure and customize Maily settings:

…

You can use the following format too:

ruby
Maily.enabled = ENV['MAILY_ENABLED']
Maily.allow_edition = false

Templates edition (allow_edition option)

This feature was designed for the development environment. Since it's based on just a file edition, and while running in production mode, code is not reloaded between requests, Rails doesn't take into account your changes (without restarting the server). Actually, allowing arbitrary Ruby code evaluation is potentially dangerous, and that's not a good idea in production.

So, template edition is not allowed outside of the development environment.

Hooks

Most of emails need to populate some data to consume it and do interesting things. Hooks are used to define this data via a little DSL. Hooks also accept "callable" objects to lazy load variables/data, so each email will evaluate its hooks on demand. Example:

ruby
# lib/maily_hooks.rb

user = User.new(email: '[email protected]')
lazy_user = -> { User.with_comments.first } # callable object, lazy evaluation
comment = Struct.new(:body).new('Lorem ipsum') # stub way
service = FactoryGirl.create(:service) # using fixtures with FactoryGirl

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:welcome, user, template_path: 'users')
  mailer.register_hook(:new_comment, lazy_user, comment)
end

Maily.hooks_for('PaymentNotifier') do |mailer|
  mailer.register_hook(:invoice, user, service)
end

Note that you are able to override the template_path and the template_name like can be done in Rails. You must pass these options as a hash and last argument:

ruby
Maily.hooks_for('YourMailerClass') do |mailer|
  mailer.register_hook(:a_random_email, template_path: 'notifications')
  mailer.register_hook(:another_email, template_name: 'email_base')
end

Email versions

You can add versions for special emails. This is useful in some cases where template content depends on the parameters you provide, for instance, a welcome message for trial accounts and gold accounts.

ruby
free_trial_account = -> { Account.free_trial.first }
gold_account = -> { Account.gold.first }

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:welcome, free_trial_account, version: 'Free trial account')
  mailer.register_hook(:welcome, gold_account, version: 'Gold account')
end

Email description

You can add a description to any email and it will be displayed along with its preview. This is useful in some cases like: someone from another team, for example, a marketing specialist, visiting Maily to review some texts and images; they can easily understand when this email is sent by the system.

ruby
Maily.hooks_for('BookingNotifier') do |mailer|
  mailer.register_hook(:accepted, description: "This email is sent when a reservation has been accepted by the system." )
end

Hide emails

You are also able to hide emails:

ruby
Maily.hooks_for('Notifier') do |mailer|
  mailer.hide_email(:sensible_email, :secret_email)
end

Use params

Support for ActionMailer::Parameterized is possible via with_params hash:

ruby
message = -> { 'Hello!' }

Maily.hooks_for('Notifier') do |mailer|
  mailer.register_hook(:new_message, with_params: { message: message })
end

External emails

If you want to register and display in the UI, emails from external sources, like for example a gem, you can do it by adding a hook. Example:

ruby
Maily.hooks_for('Devise::Mailer') do |mailer|
  mailer.hide_email(:unlock_instructions)

  mailer.register_hook(:reset_password_instructions, user, 'random_token')
  mailer.register_hook(:confirmation_instructions, user, 'random_token')
  mailer.register_hook(:password_change, user)
end

Authorization

Basically, you have 2 ways to restrict access to the Maily section. You can even combine both.

Custom base controller

By default Maily runs under ActionController::Base, but you are able to customize that parent controller (Maily.base_controller option) in order to achieve (using, for example, before_action blocks) a kind of access control system. For example, set a different base controller:

ruby
Maily.base_controller = '::SuperAdminController'

And then write your own authorization rules in this defined controller:

ruby
class SuperAdminController  bundle exec rspec

Run the test suite against all supported versions:

> bundle exec appraisal install
> bundle exec appraisal rspec

Run specs against specific version:

> bundle exec appraisal rails-6.0 rspec

Demo

Start a sample Rails app (source code) with Maily integrated:

> bundle exec rake web # PORT=4000 (default: 3000)

License

Copyright (c) Marc Anguera. Maily is released under the MIT License.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyemail-deliveryemail-previewhooksrails

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

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