-
Notifications
You must be signed in to change notification settings - Fork 12
Use with Devise
Meyric Rawlings edited this page May 3, 2024
·
4 revisions
If you're using Devise, you can overwrite your Devise mailer to use mail-notify for password reset emails etc. This is not a feature of Mail::Notify we are just a custom mailer.
You should read and understand how to customise the mailer Devise first, but a summary:
Your custom Devise mailer will need to inherit from both Mail::Notify::Mailer
and Devise::Mailer
, the simplest way to do this is:
Have your ApplicationMailer
inherit from Notify::Mailer
:
class ApplicationMailer < Mail::Notify::Mailer
end
Configure Devise to use a custom mailer and to inherit from ApplicationMailer
(which now inherits Mail::Notify::Mailer
):
In config/initializers/devise.rb
:
config.mailer = 'MyCustomDeviseMailer'
config.parent_mailer = 'ApplicationMailer'
Your custom mailer then uses either template_mail
or view_email
:
class MyCustomDeviseMailer < Devise::Mailer
def devise_mail(record, action, opts = {}, &block)
initialize_from_record(record)
template_mail("NOTIFY_TEMPLATE_ID", headers_for(action, opts))
end
end
or
class MyCustomDeviseMailer < Devise::Mailer
def devise_mail(record, action, opts = {}, &block)
initialize_from_record(record)
view_mail("NOTIFY_TEMPLATE_ID", headers_for(action, opts))
end
end