GithubHelp home page GithubHelp logo

benjamin-hull / letter_opener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ryanb/letter_opener

0.0 2.0 0.0 142 KB

Preview mail in the browser instead of sending.

License: MIT License

Ruby 85.16% HTML 14.84%

letter_opener's Introduction

Preview email in the default browser instead of sending it. This means you do not need to set up email delivery in your development environment, and you no longer need to worry about accidentally sending a test email to someone else’s address.

Rails Setup

First add the gem to your development environment and run the bundle command to install it.

gem "letter_opener", :group => :development

Then set the delivery method in config/environments/development.rb

config.action_mailer.delivery_method = :letter_opener

Now any email will pop up in your browser instead of being sent. The messages are stored in tmp/letter_opener. If you want to change application that will be used to open your emails you should override LAUNCHY_APPLICATION environment variable or set Launchy.application in the initializer.

Rails Configuration

To override the location for message storage, set the LETTER_OPENER_LOCATION environment variable.

You can set LETTER_OPENER_MESSAGE_TEMPLATE environment variable to set the template for previewing mails. The built-in templates are:

  • default The default type displays the message headers, including subject, sender and recipient, and any attachments.

  • message_only Renders only the message body, without any metadata or extra containers or styling.

Set LETTER_OPENER_MESSAGE_TEMPLATE to a path to a template file to supply your own template.

For Rails 2.3.x support

There is a fork that add support for Rails 2.3.x, in order to use that or just check it out you should go to github.com/cavi21/letter_opener

Non Rails Setup

If you aren’t using Rails, this can be easily set up with the Mail gem. Just set the delivery method when configuring Mail and specify a location.

require "letter_opener"
Mail.defaults do
  delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
end

The method is similar if you’re using the Pony gem:

require "letter_opener"
Pony.options = {
  :via => LetterOpener::DeliveryMethod,
  :via_options => {:location => File.expand_path('../tmp/letter_opener', __FILE__)}
}

Alternatively, if you are using ActionMailer directly (without Rails) you will need to add the delivery method.

require "letter_opener"
ActionMailer::Base.add_delivery_method :letter_opener, LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
ActionMailer::Base.delivery_method = :letter_opener

Remote Alternatives

Letter Opener uses Launchy to open sent mail in the browser. This assumes the Ruby process is running on the local development machine. If you are using a separate staging server or VM this will not work. In that case consider using Mailtrap or MailCatcher.

In order to keep this project simple, I don’t have plans to turn it into a Rails engine with an interface for browsing the sent mail but there is a gem you can use for that.

Development & Feedback

Questions or problems? Please use the issue tracker. If you would like to contribute to this project, fork this repository and run bundle and rake to run the tests. Pull requests appreciated.

Special thanks to the mail_view gem for inspiring this project and for their mail template. Also thanks to Vasiliy Ermolovich for helping manage this project.

letter_opener's People

Contributors

nashby avatar ryanb avatar davidcornu avatar tricknotes avatar wesgibbs avatar tylercollier avatar scarver2 avatar sj26 avatar phallstrom avatar mkdynamic avatar koic avatar kmcphillips avatar jeanmertz avatar fgrehm avatar clairemcginty avatar nono avatar benjamin-hull avatar amatsuda avatar durrantm avatar boone avatar subelsky avatar nikitachernov avatar pcg79 avatar pbougie avatar pusewicz avatar ryanlecompte avatar stevenharman avatar gurgeous avatar danielmbarlow avatar sanemat avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.