diff --git a/README.md b/README.md index 36b5bf1..8fed9e0 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,15 @@ All exceptions are reported automatically. No additional code required. Please consult the [official guides](https://guides.rubyonrails.org/error_reporting.html) for an introduction to the error reporting API. +## Optional configuration + +Set a custom from address. + +```ruby +# default: "no-reply@example.com" +config.email_error_reporter.from = "your-custom-email@example.com" +``` + ## Test your setup You can use the built-in rake task `rake email_error_reporter:check` to check if everything works correctly in your setup. diff --git a/lib/email_error_reporter/engine.rb b/lib/email_error_reporter/engine.rb index b914d07..b0d84c2 100644 --- a/lib/email_error_reporter/engine.rb +++ b/lib/email_error_reporter/engine.rb @@ -4,6 +4,7 @@ class Engine < ::Rails::Engine config.email_error_reporter = ActiveSupport::OrderedOptions.new config.email_error_reporter.to = [] + config.email_error_reporter.from = "no-reply@example.com" initializer "email_error_reporter.error_subscribe" do Rails.error.subscribe(Subscriber.new) diff --git a/lib/email_error_reporter/error_mailer.rb b/lib/email_error_reporter/error_mailer.rb index c560523..0df2c2a 100644 --- a/lib/email_error_reporter/error_mailer.rb +++ b/lib/email_error_reporter/error_mailer.rb @@ -17,6 +17,7 @@ def error(error, handled:, severity:, context:, source: nil) mail( subject: "#{severity_to_emoji.fetch(@severity)} #{error.class}", + from: Rails.application.config.email_error_reporter.from, to: Rails.application.config.email_error_reporter.to ) end