3

I want to customize devise confirmation mail subject with dynamic content.

I have tried to achieve that by using this link.

There is no change. It is taking the "Confirmation Instructions" string from devise.en.yml. then I have changed in devise.en.yml file. It has been reflected but anyway It is static change. But I need to change the subject with dynmaic content.

Please guide me to fix this issue.

RoRnetwork
  • 25
  • 7
Shan
  • 633
  • 4
  • 20

1 Answers1

4

I fixed this issue by creating a subclass of Devise::Mailer

 class DeviseMailer < Devise::Mailer
   def reset_password_instructions(record, token, opts={})
     mail = super
     # custom logic
     mail.subject = "[Dynamic Subject]"
     mail
   end
 end

and customized devise.rb in initializer to call the custom emailer

config.mailer = 'DeviseMailer' 
Shan
  • 633
  • 4
  • 20
  • Credit for the original answer should go here: https://stackoverflow.com/a/21344142/165673 – Yarin Dec 24 '18 at 23:58