Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add OverrideRecipientSMTP to staging environment

  • Loading branch information...
commit d3d6e5ff18cb195b421a91ccf1c869012a76b120 1 parent 8290c97
@croaky croaky authored
View
1  README.md
@@ -50,6 +50,7 @@ Other goodies
Suspenders also comes with:
+* Override recipient emails in staging environment.
* Rails' flashes set up and in application layout.
* A few nice time formats.
* [Heroku-recommended asset pipeline
View
3  lib/suspenders/app_builder.rb
@@ -25,6 +25,9 @@ def enable_factory_girl_syntax
def setup_staging_environment
run 'cp config/environments/production.rb config/environments/staging.rb'
+ inject_into_file 'config/environments/staging.rb',
+ "\n config.action_mailer.delivery_method = :override_recipient_smtp, to: 'staging@example.com'",
@calebthompson Admin

This line is causing an error. It appears that you're passing an argument list but assigning to a variable.

@croaky Admin
croaky added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ :after => 'config.action_mailer.raise_delivery_errors = false'
end
def initialize_on_precompile
View
38 templates/override_recipient_smtp.rb
@@ -0,0 +1,38 @@
+module Mail
+ # == Sending Email with Override Recipient SMTP
+ #
+ # Use the OverrideRecipientSMTP delivery method when you don't want your app
+ # to accidentally send emails to addresses other than the overridden recipient
+ # which you configure.
+ #
+ # An typical use case is in your app's staging environment, your development
+ # team will receive all staging emails without accidentally emailing users with
+ # active email addresses in the database.
+ #
+ # === Sending via OverrideRecipientSMTP
+ #
+ # config.action_mailer.delivery_method = :override_recipient_smtp,
+ # to: 'staging@example.com'
+ #
+ # === Sending to multiple email addresses
+ #
+ # config.action_mailer.delivery_method = :override_recipient_smtp,
+ # to: ['dan@example.com', 'harlow@example.com']
+ class OverrideRecipientSMTP < Mail::SMTP
+ def initialize(values)
+ unless values[:to]
+ raise ArgumentError.new('A :to option is required when using :override_recipient_smtp')
+ end
+
+ super(values)
+ end
+
+ def deliver!(mail)
+ mail.to = settings[:to]
+ mail.cc = nil
+ mail.bcc = nil
+
+ super(mail)
+ end
+ end
+end
@calebthompson

This line is causing an error. It appears that you're passing an argument list but assigning to a variable.

@croaky
Please sign in to comment.
Something went wrong with that request. Please try again.