Letter opener with a web interface

Public
An interface for browsing sent emails
Icons/chart bar
Used 58 times
Created by
V Viktor Schmidt

Usage
RubyGems: https://rubygems.org/gems/letter_opener
https://rubygems.org/gems/letter_opener_web

When mail is sent from your application, Letter Opener will open a preview in the browser instead of sending. letter_opener_web gem gives letter_opener an interface for browsing sent emails.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/X6kseb"
Template Source

Review the code before running this template on your machine.

def do_bundle
  Bundler.with_unbundled_env { run "bundle install" }
end

def print_green(heredoc)
  puts set_color heredoc, :green
end

def do_commit
  git :init
  git add: "."
  Bundler.with_unbundled_env { git commit: " -m 'Add Letter Opener with a web interface' " }
end

say "\nApplying Letter Opener with a web interface..."
inject_into_file 'Gemfile', after: 'group :development do' do
  <<-RUBY 

  # An interface for browsing sent emails
  gem "letter_opener_web"
  RUBY
end

do_bundle

inject_into_file "config/routes.rb", after: "Rails.application.routes.draw do\n" do
  <<-RUBY 
  # Mount LetterOpener web, in order to open sended email previews in the browser
  mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?

  RUBY
end

inject_into_file "config/environments/development.rb", after: "config.action_mailer.perform_caching = false\n" do
  <<-RUBY 

  # just want to browse mails using the web interface and don't care about opening emails automatically
  config.action_mailer.delivery_method = :letter_opener_web
  config.action_mailer.perform_deliveries = true
  RUBY
end

run "bin/rubocop -AS"
do_commit

print_green "\nAdded Letter Opener with a web interface successfully!"
Comments

Sign up or Login to leave a comment.