Project

postmortem

0.0
The project is in a healthy, maintained state
Preview HTML emails in your browser during development
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

Postmortem

Postmortem provides a simple and clean preview of all outgoing mails sent by your Ruby application to make email development a little less painful.

Every time your application sends an email a clearly-visible log entry will be written which provides a path to a temporary file containing your preview.

Take a look at a live example to see Postmortem in action.

Postmortem should only be enabled in test or development environments.

Features

  • Seamless integration with ActionMailer, Pony, Mail, etc.
  • Email deliveries are always intercepted (can be configured to pass through).
  • Preview email content as well as typical email headers (recipients, subject, etc.).
  • View rendered HTML, plaintext, or HTML source with syntax highlighting (courtesy of highlight.js).
  • Dual or single column view to suit your requirements.
  • Content is loaded inside an <iframe> to ensure document isolation and validity.

Installation

Add the gem to your application's Gemfile:

group :development, :test do
  gem 'postmortem', '~> 0.2.1'
end

And then execute:

$ bundle install

Or install it yourself as:

$ gem install postmortem

Usage

Postmortem automatically integrates with Rails ActionMailer and Pony. When an email is sent an entry will be visible in your application's log output.

The path to the preview file is based on the current time and the subject of the email. If you would prefer to use the same path for each email you can disable timestamps (see configuration) and simply reload your browser every time an email is sent.

If you are using assets (images etc.) with ActionMailer make sure to configure the asset host, e.g.:

# config/environments/development.rb
Rails.application.configure do
  config.action_mailer.asset_host = 'http://localhost:3000'
end

Load the provided file in your browser to preview your email.

Screenshot

Configuration

Configure Postmortem by calling Postmortem.configure, e.g. in a Rails initializer.

# config/initializers/postmortem.rb
Postmortem.configure do |config|
  # Colorize output in logs (path to preview HTML file) to improve visibility (default: true).
  config.colorize = true

  # Path to the Postmortem log file, where preview paths are written (default: STDOUT).
  config.log_path = '/path/to/postmortem.log'

  # Path to save preview .html files (default: OS-provided temp directory).
  # The directory will be created if it does not exist.
  config.preview_directory = '/path/to/postmortem/directory'

  # Provide a custom layout path if the default interface does not suit you.
  # See `layout/default.html.erb` for implementation reference.
  config.layout = '/path/to/layout'

  # Skip delivery of emails when using Pony, Mail, etc. (default: true).
  config.mail_skip_delivery = true
end

Contributing

Feel free to make a pull request.

License

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