# rails_email_preview **Repository Path**: mirrors_GUI/rails_email_preview ## Basic Information - **Project Name**: rails_email_preview - **Description**: Preview and edit app mailer templates in Rails. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-08 - **Last Updated**: 2026-01-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Rails Email Preview [![Build Status][badge-ci]][ci] [![Test Coverage][coverage-badge]][coverage] [![Code Climate][codeclimate-badge]][codeclimate] [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/glebm/rails_email_preview?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Preview email in the browser with this Rails engine. Compatible with Rails 6.1+. An email review: ![screenshot][rep-show-screenshot] The list of all email previews: ![screenshot][rep-nav-screenshot] REP comes with two themes: a simple standalone theme, and a theme that uses [Bootstrap 3][rep-show-default-screenshot]. ## Installation Add [![Gem Version][gem-badge]][gem] to Gemfile: ```ruby gem 'rails_email_preview', '~> 2.2.3' ``` This gem requires a Sass engine, please ensure you have **one** of these gems in your Gemfile: - [`dartsass-sprockets`](https://github.com/tablecheck/dartsass-sprockets): Dart Sass engine, recommended but only works for Ruby 2.6+ and Rails 5+ - [`dartsass-rails`](https://github.com/rails/dartsass-rails): Dart Sass engine, recommended for Rails projects that use Propshaft - [`cssbundling-rails`](https://github.com/rails/cssbundling-rails): External Sass engine - [`sassc-rails`](https://github.com/sass/sassc-rails): SassC engine, deprecated but compatible with Ruby 2.3+ and Rails 4 Add an initializer and the routes: ```console $ rails g rails_email_preview:install ``` Generate preview classes and method stubs in app/mailer_previews/ ```console $ rails g rails_email_preview:update_previews ``` ## Usage The last generator above will add a stub for each of your emails, then you populate the stubs with mock data: ```ruby # app/mailer_previews/user_mailer_preview.rb: class UserMailerPreview # preview methods should return Mail objects, e.g.: def invitation UserMailer.invitation mock_user('Alice'), mock_user('Bob') end def welcome UserMailer.welcome mock_user end private # You can put all your mock helpers in a module # or you can use your factories / fabricators, just make sure you are not creating anything def mock_user(name = 'Bill Gates') fake_id User.new(name: name, email: "user#{rand 100}@test.com") end def fake_id(obj) # overrides the method on just this object obj.define_singleton_method(:id) { 123 + rand(100) } obj end end ``` ### Parameters as instance variables All parameters in the search query will be available to the preview class as instance variables. For example, if URL to mailer preview looks like: /emails/user_mailer_preview-welcome?**user_id=1** The method `welcome` in `UserMailerPreview` have a `@user_id` instance variable defined: ```ruby class UserMailerPreview def welcome user = @user_id ? User.find(@user_id) : mock_user UserMailer.welcome(user) end end ``` Now you can preview or send the welcome email to a specific user. ### Routing You can access REP urls like this: ```ruby # engine root: rails_email_preview.rep_root_url # list of emails (same as root): rails_email_preview.rep_emails_url # email show: rails_email_preview.rep_email_url('user_mailer-welcome') ``` ### Sending Emails You can send emails via REP. This is especially useful when testing with limited clients (Blackberry, Outlook, etc.). This will use the environment's mailer settings, but the handler will `perform_deliveries`. Uncomment this line in the initializer to disable sending test emails: ```ruby config.enable_send_email = false ``` ### Editing Emails Emails can be stored in the database and edited in the browser. REP works with [Comfortable Mexican Sofa CMS](https://github.com/comfy/comfortable-mexican-sofa) to achieve this -- see the [CMS Guide](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa) to learn more. [![screenshot](https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-edit-sofa.png)](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa) ### CSS inlining For CSS inlining, REP supports [Roadie](https://github.com/Mange/roadie) and [Premailer](https://github.com/alexdunae/premailer). Both of these automatically translate CSS rules into inline styles and turn relative URLs into absolute ones. Roadie additionally extracts styles that cannot be inlined into a separate `