Skip to content

Commit

Permalink
Remove action_mailer
Browse files Browse the repository at this point in the history
We're no longer using `ActionMailer` to send emails so we can safely
remove code that references it.
  • Loading branch information
thomasleese committed Jan 17, 2025
1 parent 959d7b7 commit e8250aa
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 65 deletions.
10 changes: 6 additions & 4 deletions app/jobs/notify_delivery_job.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

require "notifications/client"

class NotifyDeliveryJob < ApplicationJob
queue_as { Rails.configuration.action_mailer.deliver_later_queue_name }
queue_as :mailer

def self.client
@client ||=
Notifications::Client.new(
Rails.configuration.action_mailer.notify_settings[:api_key]
Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"]
)
end

Expand All @@ -15,11 +17,11 @@ def self.deliveries
end

def self.send_via_notify?
Rails.configuration.action_mailer.delivery_method == :notify
Settings.govuk_notify&.enabled
end

def self.send_via_test?
Rails.configuration.action_mailer.delivery_method == :test
Rails.env.test?
end

class UnknownTemplate < StandardError
Expand Down
2 changes: 0 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class Application < Rails::Application
config.active_job.queue_adapter = :good_job
config.good_job.execution_mode = :async

config.action_mailer.deliver_later_queue_name = :mailer

config.view_component.default_preview_layout = "component_preview"
config.view_component.preview_controller = "ComponentPreviewsController"
config.view_component.preview_paths << Rails.root.join(
Expand Down
19 changes: 0 additions & 19 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Make template changes take effect immediately.
config.action_mailer.perform_caching = false

# Set localhost to be used by links generated in mailer templates.
config.action_mailer.default_url_options = { host: "localhost", port: 4000 }

if Settings.govuk_notify&.enabled
config.action_mailer.delivery_method = :notify
config.action_mailer.notify_settings = {
api_key: Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"]
}
else
config.action_mailer.default_options = { from: "[email protected]" }
config.action_mailer.delivery_method = :file
end

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

Expand Down
21 changes: 0 additions & 21 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,6 @@
# Replace the default in-process and non-durable queuing backend for Active Job.
# config.active_job.queue_adapter = :resque

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = {
host:
if Settings.is_review
"#{ENV["HEROKU_APP_NAME"]}.herokuapp.com"
else
Settings.host
end,
protocol: "https"
}

# Configure GOV.UK Notify.
config.action_mailer.delivery_method = :notify
config.action_mailer.notify_settings = {
api_key: Settings.govuk_notify.live_key
}

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
Expand Down
4 changes: 0 additions & 4 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@
description: "Track the status of DPS exports"
}
)

config.action_mailer.notify_settings = {
api_key: Settings.govuk_notify["#{Settings.govuk_notify.mode}_key"]
}
end
9 changes: 0 additions & 9 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@
# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = { host: "localhost:4000" }
config.action_mailer.default_options = { from: "[email protected]" }

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

Expand Down
4 changes: 4 additions & 0 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ cis2:
issuer: "http://localhost:4000/test/oidc"
client_id: "31337.apps.national"

govuk_notify:
enabled: false
mode: test

mesh:
base_url: https://localhost:8700
disable_ssl_verification: true
Expand Down
6 changes: 3 additions & 3 deletions spec/jobs/email_delivery_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe EmailDeliveryJob do
before(:all) do
Rails.configuration.action_mailer.delivery_method = :notify
Rails.configuration.action_mailer.notify_settings = { api_key: "abc" }
Settings.govuk_notify.enabled = true
Settings.govuk_notify.test_key = "abc"
end

after(:all) { Rails.configuration.action_mailer.delivery_method = :test }
after(:all) { Settings.govuk_notify.enabled = false }

let(:response) do
instance_double(
Expand Down
6 changes: 3 additions & 3 deletions spec/jobs/sms_delivery_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

describe SMSDeliveryJob do
before(:all) do
Rails.configuration.action_mailer.delivery_method = :notify
Rails.configuration.action_mailer.notify_settings = { api_key: "abc" }
Settings.govuk_notify.enabled = true
Settings.govuk_notify.test_key = "abc"
end

after(:all) { Rails.configuration.action_mailer.delivery_method = :test }
after(:all) { Settings.govuk_notify.enabled = false }

let(:response) do
instance_double(
Expand Down

0 comments on commit e8250aa

Please sign in to comment.