From 218519d0750e1718bd55d0d1517295b6ee7be483 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 26 Aug 2025 10:21:13 +0200 Subject: [PATCH] Configure letter opener --- Gemfile | 1 + Gemfile.lock | 9 +++++++++ README.md | 13 +++++++++++++ config/environments/development.rb | 8 ++++++-- lib/tasks/.keep | 0 lib/tasks/dev.rake | 16 ++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) delete mode 100644 lib/tasks/.keep create mode 100644 lib/tasks/dev.rake diff --git a/Gemfile b/Gemfile index 933cb4e61..2518d7495 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,7 @@ group :development, :test do gem "bundler-audit", require: false gem "brakeman", require: false gem "rubocop-rails-omakase", require: false + gem "letter_opener" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index dbb76fd31..d3be19716 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -276,6 +276,8 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + childprocess (5.1.0) + logger (~> 1.5) chunky_png (1.4.0) concurrent-ruby (1.3.5) connection_pool (2.5.3) @@ -342,6 +344,12 @@ GEM jwt (3.1.2) base64 language_server-protocol (3.17.0.5) + launchy (3.1.1) + addressable (~> 2.8) + childprocess (~> 5.0) + logger (~> 1.6) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) lint_roller (1.1.0) logger (1.7.0) loofah (2.24.1) @@ -611,6 +619,7 @@ DEPENDENCIES importmap-rails jbuilder kamal! + letter_opener lexxy! mission_control-jobs mocha diff --git a/README.md b/README.md index 58a1a9682..9fc392287 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,19 @@ A typical scenario is making modifications LLM prompts. You need to: Notice that if you pass changing data to the prompt, this mechanism won't work. E.g: if you pass data timestamps. You need to make sure those timestamps are always the same across executions. +### Outbound Emails + +#### Development + +You can view email previews at http://know-it-all.localhost:3005/rails/mailers. + +You can enable or disable [`letter_opener`](https://github.com/ryanb/letter_opener) to +open sent emails automatically with: + + bin/rails dev:email + +Under the hood, this will create or remove `tmp/email-dev.txt`. + ## Environments Fizzy is deployed with Kamal. You'll need to have the 1Password CLI set up in order to access the secrets that are used when deploying. Provided you have that, it should be as simple as `bin/kamal deploy` to the correct environment. diff --git a/config/environments/development.rb b/config/environments/development.rb index 002ee99ed..0703601ec 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -72,8 +72,12 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true - # Allow all hosts in development - config.hosts = nil + if Rails.root.join("tmp/email-dev.txt").exist? + config.action_mailer.delivery_method = :letter_opener + config.action_mailer.perform_deliveries = true + else + config.action_mailer.raise_delivery_errors = false + end config.hosts = %w[ fizzy.localhost localhost 127.0.0.1 ] diff --git a/lib/tasks/.keep b/lib/tasks/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake new file mode 100644 index 000000000..07dfef697 --- /dev/null +++ b/lib/tasks/dev.rake @@ -0,0 +1,16 @@ +namespace :dev do + desc "Toggle using Letter Opener to preview emails" + task :email do + file_path = Rails.root.join("tmp", "email-dev.txt") + + if File.exist?(file_path) + File.delete(file_path) + puts "Letter Opener turned off" + else + FileUtils.touch(file_path) + puts "Letter Opener turned on" + end + + %x(bin/rails restart) + end +end