diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index ed5786eead..2adab7b82b 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,6 +1,5 @@ class ApplicationMailer < ActionMailer::Base append_view_path Rails.root.join('app', 'views', 'mailers') - default from: 'noreply@internet.ee' layout 'mailer' def format(email) diff --git a/config/application-example.yml b/config/application-example.yml index 8fcb2c944c..b19d65bdb6 100644 --- a/config/application-example.yml +++ b/config/application-example.yml @@ -145,6 +145,7 @@ auction_api_allowed_ips: '' # 192.0.2.0, 192.0.2.1 action_mailer_default_protocol: # default: http action_mailer_default_host: action_mailer_default_port: # default: no port (80) +action_mailer_default_from: # no-reply@example.com # Since the keys for staging are absent from the repo, we need to supply them separate for testing. test: @@ -153,6 +154,7 @@ test: release_domains_to_auction: 'false' auction_api_allowed_ips: '' action_mailer_default_host: 'registry.test' + action_mailer_default_from: 'no-reply@registry.test' # Airbrake // Errbit: airbrake_host: "https://your-errbit-host.ee" diff --git a/config/application.rb b/config/application.rb index 2d6ced728f..618340b05d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -90,6 +90,7 @@ class Application < Rails::Application domain: ENV['smtp_domain'], openssl_verify_mode: ENV['smtp_openssl_verify_mode'] } + config.action_mailer.default_options = { from: ENV['action_mailer_default_from'] } config.action_view.default_form_builder = 'DefaultFormBuilder' config.secret_key_base = Figaro.env.secret_key_base diff --git a/config/initializers/figaro.rb b/config/initializers/figaro.rb index cc25a71687..44c830eeab 100644 --- a/config/initializers/figaro.rb +++ b/config/initializers/figaro.rb @@ -12,4 +12,5 @@ bank_statement_import_dir time_zone action_mailer_default_host + action_mailer_default_from ]) diff --git a/test/mailers/application_mailer_test.rb b/test/mailers/application_mailer_test.rb new file mode 100644 index 0000000000..e54bce4c33 --- /dev/null +++ b/test/mailers/application_mailer_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' + +class ApplicationMailerTest < ActiveSupport::TestCase + def test_reads_default_from_setting_from_config + assert_equal 'no-reply@registry.test', ENV['action_mailer_default_from'] + + mailer = Class.new(ApplicationMailer) do + def test + # Empty block to avoid template rendering + mail {} + end + end + email = mailer.test + + assert_equal ['no-reply@registry.test'], email.from + end +end \ No newline at end of file