Skip to content

Instantly share code, notes, and snippets.

@lcguida
Last active January 27, 2017 13:03
Show Gist options
  • Save lcguida/db303d87a1b1afeff02b7dcf636a5887 to your computer and use it in GitHub Desktop.
Save lcguida/db303d87a1b1afeff02b7dcf636a5887 to your computer and use it in GitHub Desktop.
Custom delivery method to replace recipient on sendmail for a staging environment
# lib/utils/sendmail_staging.rb
class SendmailStaging < ::Mail::Sendmail
# mail object can be used to modify mail before we pass it
# to sendmail
def deliver!(mail)
mail['to'] = '[email protected]' #replace recipient
super(mail) #Let Sendmail do his work
end
end
# config/initializers/sendmail_staging_delivery_method.rb
# Register the custom delivery method:
ActionMailer::Base.add_delivery_method :sendmail_staging, SendmailStaging
# config/environment/staging.rb
Rails.application.configure do
# ... other configs ...
config.action_mailer.delivery_method = :sendmail_staging
# ... other configs ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment