diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index a289acf..a9ccecf 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base + default Rails.application.config.action_mailer.default_options layout 'mailer' private @@ -19,7 +20,7 @@ class ApplicationMailer < ActionMailer::Base end def from_address - ENV.fetch('SMTP_FROM_ADDRESS', 'accounts@localhost') + self.class.default[:from] end def from_domain diff --git a/config/environments/development.rb b/config/environments/development.rb index 9f73578..a5b46ac 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -57,16 +57,22 @@ Rails.application.configure do # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker - config.action_mailer.default_options = { - from: "accounts@localhost" - } - # Don't actually send emails, cache them for viewing via letter opener config.action_mailer.delivery_method = :letter_opener + # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true + # Base URL to be used by email template link helpers - config.action_mailer.default_url_options = { host: "localhost:3000", protocol: "http" } + config.action_mailer.default_url_options = { + host: "localhost:3000", + protocol: "http" + } + + config.action_mailer.default_options = { + from: "accounts@localhost", + message_id: -> { "<#{Mail.random_tag}@localhost>" }, + } # Allow requests from any IP config.web_console.permissions = '0.0.0.0/0' diff --git a/config/environments/production.rb b/config/environments/production.rb index 16e7fa5..da0fa6f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -63,7 +63,7 @@ Rails.application.configure do outgoing_email_domain = Mail::Address.new(outgoing_email_address).domain config.action_mailer.default_url_options = { - host: ENV['AKKOUNTS_DOMAIN'], + host: ENV.fetch('AKKOUNTS_DOMAIN'), protocol: "https", } diff --git a/config/environments/test.rb b/config/environments/test.rb index 65473dd..0c474bf 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -46,8 +46,12 @@ Rails.application.configure do config.action_mailer.default_url_options = { host: "accounts.kosmos.org", - protocol: "https", - from: "accounts@kosmos.org" + protocol: "https" + } + + config.action_mailer.default_options = { + from: "accounts@kosmos.org", + message_id: -> { "<#{Mail.random_tag}@kosmos.org>" }, } config.active_job.queue_adapter = :test