How can I customize Devise to send password reset emails using PostMark mailer

前端 未结 3 884
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 04:57

I\'m trying to get all of my system\'s email notifications under one umbrella using PostMarkApp and utilizing the Rails gems (postmark-rails, postmark-gem, and mail). I have

3条回答
  •  一个人的身影
    2020-12-13 05:26

    Using the latest version of Devise, the methods above didn't help me. This is my solution.

    In config/application.rb:

    config.action_mailer.delivery_method   = :postmark
    config.action_mailer.postmark_settings = { :api_key => "your-API-key-here" }
    

    In config/initializers/devise.rb:

    config.mailer = "UserMailer" # UserMailer is my mailer class
    

    In app/mailers/user_mailer.rb:

    class UserMailer < ActionMailer::Base
      include Devise::Mailers::Helpers
    
      default from: "default@mydomain.com"
    
      def confirmation_instructions(record)
        devise_mail(record, :confirmation_instructions)
      end
    
      def reset_password_instructions(record)
        devise_mail(record, :reset_password_instructions)
      end
    
      def unlock_instructions(record)
        devise_mail(record, :unlock_instructions)
      end
    
      # you can then put any of your own methods here
    end
    

    Finally, make sure you have generated custom devise views

    rails generate devise:views
    

    and move the email templates from app/views/devise/mailer/ to app/views/user_mailer/

    mv app/views/devise/mailer/* app/views/user_mailer/
    

提交回复
热议问题