I am using Devise in a Rails 3 application to create accounts. I have different types of users, so I want to send out custom password recovery emails based on the type of user.
I am able to send the custom email, I haven't found a way to set custom headers on that email. I am particularly interested in setting the subject of the email.
I have done the following:
devise_mail
.My custom mailer looks like this:
class AccountMailer < Devise::Mailer
helper :application # gives access to all helpers defined within application_helper.
def reset_partner_instructions(record, opts={})
devise_mail(record, :reset_partner_instructions, opts)
end
end
The problem is that the subject of the email is always "Reset partner instructions". I believe Devise is generating this title from the name of the mail template.
In this tutorial https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer, they call the following code:
def confirmation_instructions(record, opts={})
headers["Custom-header"] = "Bar"
super
end
Since I'm calling "devise_mail" directly, I'm not seeing how to pass the headers intoto the mailer. Is there a simple setting or method I can use to set the email subject?
This is an old question but still comes up at the top of search and I was able to solve this by setting opts[:subject]
instead of setting the header:
# https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer
class DeviseMailer < Devise::Mailer
helper :application
include Devise::Controllers::UrlHelpers
default template_path: 'devise/mailer'
def confirmation_instructions(record, token, opts={})
opts[:subject] = ...
opts[:from] = ...
opts[:reply_to] = ...
super
end
end
And in devise.rb
:
config.mailer = 'DeviseMailer'
See devise helper
class AccountMailer < Devise::Mailer
def confirmation_instructions(record, opts={})
headers = {
:subject => "Subject Here"
}
super
end
end
Or you can change it in devise.en.yml
file in intilizer directory
And set your own subject
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
It is very old question, it may be helpful still for you are others,
for custom subject:
add the content like this as shown below, make sure you do the indentation properly with 2 spaces as you do in database.yml file.
en:
devise:
mailer:
confirmation_instructions:
subject: 'Verification subject here'
reset_password_instructions:
subject: 'Reset password subject here'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With