Skip to content

Commit

Permalink
Add :send_core_emails config prefernce
Browse files Browse the repository at this point in the history
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 spree#3812
  • Loading branch information
sohara authored and huoxito committed Oct 9, 2013
1 parent b28b4ed commit a5d1d24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/app/mailers/spree/base_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions core/app/models/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '[email protected]'
preference :mail_bcc, :string, :default => '[email protected]'
preference :intercept_email, :string, :default => nil
Expand Down
9 changes: 9 additions & 0 deletions core/spec/mailers/order_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a5d1d24

Please sign in to comment.