Prefix all emails with application name and Rails ENV
Add prefix to all delivered emails containing application name and Rails environment which is helpful for setting up email filters for non-production emails.
Examples:
[MyApp] Forgot Password
[MyApp STAGING] Forgot Password
# config/initializers/add_appname_to_email_subject.rb
class AddAppnameToEmailSubject
COMPANY_NAME = 'MyApp'
def self.delivering_email(mail)
mail.subject.prepend(email_prefix)
end
def self.email_prefix
prefixes = []
prefixes << COMPANY_NAME
prefixes << Rails.env.upcase unless Rails.env.production?
"[#{prefixes.join(' ')}] "
end
end
ActionMailer::Base.register_interceptor(AddAppnameToEmailSubject)
Written by Ryan Sonnek
Related protips
2 Responses
You could initialize the prefixes with company_name
def self.email_prefix
prefixes = [COMPANY_NAME]
....
end
over 1 year ago
·
This code now has an official home in the email_prefixer gem!
https://github.com/wireframe/email_prefixer
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#