Search code examples
ruby-on-railsdevisemailer

Rails + Devise => Use Devise Mailer globally to handle all of the mail sending?


I would like to use the devise mailer globally, since that way I would not have to add another mailer to my app and just use the devise one, to send custom mails outside the devise views/controllers.

Already digged to long for this, anyone know how I can make this possible?


Solution

  • If the point is to only have one mailer, it's perhaps more straightforward to have your one single mailer just extend the DeviseMailer. E.g. in app/mailer

    # app/mailers/mailer.rb
    class Mailer < Devise::Mailer
    
      # add all your custom mailer methods
    end
    

    This setup will, for example, cause all emails (from Devise and otherwise) to all be sent with the app/layouts/mailer.html.erb template.

    Note that to do this you do need to move the Devise mailer templates from app/views/devise/mailer to just app/views/mailer.