From a5d1d2448d171717fc5aa5bc08c4c72fcc3f687c Mon Sep 17 00:00:00 2001 From: Sean O'Hara Date: Wed, 2 Oct 2013 15:16:45 -0400 Subject: [PATCH] Add :send_core_emails config prefernce Allow developers to use standard rails mail configuration (in config files) by setting :override_actionmailer_config to false without sending spree core emails (e.g. order confirmation). This is useful e.g. in the case where devs have opted to use an external mail API such as Mandrill for store-related emails but still want to use ActionMailer in other parts of their app. Fixes #3812 --- core/app/mailers/spree/base_mailer.rb | 5 +++++ core/app/models/spree/app_configuration.rb | 1 + core/spec/mailers/order_mailer_spec.rb | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/core/app/mailers/spree/base_mailer.rb b/core/app/mailers/spree/base_mailer.rb index 7d35ecdd432..f87322ee7c6 100644 --- a/core/app/mailers/spree/base_mailer.rb +++ b/core/app/mailers/spree/base_mailer.rb @@ -8,5 +8,10 @@ def money(amount) Spree::Money.new(amount).to_s end helper_method :money + + def mail(headers={}, &block) + super if Spree::Config[:send_core_emails] + end + end end diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb index dffaae8d07d..f9196208b88 100644 --- a/core/app/models/spree/app_configuration.rb +++ b/core/app/models/spree/app_configuration.rb @@ -85,6 +85,7 @@ class AppConfiguration < Preferences::Configuration # Default mail headers settings preference :enable_mail_delivery, :boolean, :default => false + preference :send_core_emails, :boolean, :default => true preference :mails_from, :string, :default => 'spree@example.com' preference :mail_bcc, :string, :default => 'spree@example.com' preference :intercept_email, :string, :default => nil diff --git a/core/spec/mailers/order_mailer_spec.rb b/core/spec/mailers/order_mailer_spec.rb index 44d13cd3427..6c118745a77 100644 --- a/core/spec/mailers/order_mailer_spec.rb +++ b/core/spec/mailers/order_mailer_spec.rb @@ -108,4 +108,13 @@ end end end + + context "with preference :send_core_emails set to false" do + it "sends no email" do + Spree::Config.set(:send_core_emails, false) + message = Spree::OrderMailer.confirm_email(order) + message.body.should be_blank + end + end + end