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.
- Seamless integration with ActionMailer, Pony, Mail, etc.
- Email deliveries are always intercepted (can be configured to pass through).
- Live inbox monitors incoming emails so you can view them as soon as they are delivered.
- 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).
- Content is loaded inside an
<iframe>
to ensure document isolation and validity. - Local images are located and embedded in HTML so you can see the full version of outgoing emails.
- Runs without a server - single page app runs on file system with no need to run a local web server to access UI.
- Any captured email can be downloaded into a standalone HTML file which can be shared with others.
- Similarly, any captured eamil can also be uploaded to a stanadlone version of Postmortem at https://postmortem.delivery/
Add the gem to your application's Gemfile:
group :development, :test do
gem 'postmortem', '~> 0.3.2'
end
And then execute:
$ bundle install
Or install it yourself as:
$ gem install postmortem
PostMortem automatically integrates with Rails ActionMailer and Pony. When an email is sent an entry will be visible in your application's log output.
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
A log entry will be generated every time an email is sent. Load the path provided in the log entry in your browser to launch PostMortem:
The inbox can be cleared at any time (e.g. at the start of a test run):
Postmortem.clear_inbox
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
Feel free to make a pull request.
The gem is available as open source under the terms of the MIT License.