Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override ActionMailer subject in staging environment

I would like all the emails sent from our staging server to have the phrase "[STAGING] " prefaced in the subject. Is there an elegant way to do this in Rails 3.2 using ActionMailer?

like image 978
Jon Lemmon Avatar asked Dec 11 '12 02:12

Jon Lemmon


1 Answers

Here's an elegant solution I found using ActionMailer Interceptor based on an existing answer.

# config/initializers/change_staging_email_subject.rb
if Rails.env.staging?
  class ChangeStagingEmailSubject
    def self.delivering_email(mail)
      mail.subject = "[STAGING] " + mail.subject
    end
  end
  ActionMailer::Base.register_interceptor(ChangeStagingEmailSubject)
end
like image 112
Jon Lemmon Avatar answered Oct 05 '22 03:10

Jon Lemmon