From 35a3db85fc7a78d8b6c7fd522ab0614dacb4bfb8 Mon Sep 17 00:00:00 2001
From: erikse <erikse@users.noreply.github.com>
Date: Fri, 11 Mar 2016 17:13:06 +0000
Subject: [PATCH] Revert "Remove action mailer dependency"

---
 app/mailers/.gitkeep               | 0
 config/application.rb              | 3 ++-
 config/environments/development.rb | 3 +++
 config/environments/production.rb  | 6 ++++++
 config/environments/test.rb        | 5 +++++
 5 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 app/mailers/.gitkeep

diff --git a/app/mailers/.gitkeep b/app/mailers/.gitkeep
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/config/application.rb b/config/application.rb
index 49710b2bddb..5952462a374 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -1,8 +1,9 @@
 require File.expand_path('../boot', __FILE__)
 
-# Don't include all of rails, we don't need activerecord or action_mailer
+# Don't include all of rails, we don't need activerecord
 require "action_controller/railtie"
 require "active_model/railtie"
+require "action_mailer/railtie"
 require "sprockets/railtie"
 require "rails/test_unit/railtie"
 
diff --git a/config/environments/development.rb b/config/environments/development.rb
index cf9ac377386..8c497d80066 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -12,6 +12,9 @@
   config.consider_all_requests_local       = true
   config.action_controller.perform_caching = false
 
+  # Don't care if the mailer can't send
+  config.action_mailer.raise_delivery_errors = false
+
   # Print deprecation notices to the Rails logger
   config.active_support.deprecation = :log
 
diff --git a/config/environments/production.rb b/config/environments/production.rb
index f5a65ae68b1..1edb1ba3fb0 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -48,6 +48,9 @@
   # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
   # config.assets.precompile += %w( search.js )
 
+  # Disable delivery errors, bad email addresses will be ignored
+  # config.action_mailer.raise_delivery_errors = false
+
   # Enable threaded mode
   # config.threadsafe!
 
@@ -60,6 +63,9 @@
 
   config.action_controller.asset_host = ENV['GOVUK_ASSET_HOST']
 
+  config.action_mailer.default_url_options = { host: Plek.new.find('smartanswers') }
+  config.action_mailer.delivery_method = :ses
+
   if ENV['RUNNING_ON_HEROKU'].blank?
     # Enable JSON-style logging
     config.logstasher.enabled = true
diff --git a/config/environments/test.rb b/config/environments/test.rb
index c6da387534d..7d72a4c6c01 100644
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -23,6 +23,11 @@
   # Disable request forgery protection in test environment
   config.action_controller.allow_forgery_protection    = false
 
+  # 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
+
   # Use SQL instead of Active Record's schema dumper when creating the test database.
   # This is necessary if your schema can't be completely dumped by the schema dumper,
   # like if you have constraints or database-specific column types