如何自定义Devise发送密码重置邮件使用PostMark邮件程序 [英] How can I customize Devise to send password reset emails using PostMark mailer

查看:203
本文介绍了如何自定义Devise发送密码重置邮件使用PostMark邮件程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PostMarkApp 并利用Rails宝石( postmark-rails 邮戳宝石,和邮件)。我已经成功地创建了一个处理发送收据以进行购买的邮件,但是我还没有收到忘记密码的电子邮件。我的开发日志显示,Devise发送消息,但收件箱中没有收到电子邮件,PostMark积分不会减少。

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 successfully created a mailer that handles sending receipts for purchases but I haven't been able to receive emails for forgotten passwords. My development logs show that Devise sent the message but no email is received in my inbox and the PostMark credits are not decremented.

Devise的邮件程序是最好还是最简单的方法通过我的PostMark帐户发送

What's the best or easiest way to have Devise's mailers send through my PostMark account?

来自config / environments / development.rb的片段

config.action_mailer.delivery_method      = :postmark
config.action_mailer.postmark_settings    = { :api_key => "VALID_API_KEY_WAS_HERE" }
config.postmark_signature                 = VALID_POSTMARK_SIGNATURE_WAS_HERE

我的Mailer使用邮戳

class Notifier < ActionMailer::Base
  # set some sensible defaults
  default :from => MyApp::Application.config.postmark_signature

  def receipt_message(order)
    @order = order
    @billing_address = order.convert_billing_address_to_hash(order.billing_address)

    mail(:to => @order.user.email, :subject => "Your Order Receipt", :tag => 'order-receipt', :content_type => "text/html") do |format|
      format.html
    end
  end
end



编辑:解决我的问题在



解决方案是通过让我的通知程序 mailer扩展Devise :: Mailer并指定Devise在 config / initializers / devise.rb中使用我的通知程序作为邮件程序

SOLUTION to my question is below

Solved it by having my Notifier mailer extend Devise::Mailer and specifying Devise to use my Notifier as the mailer within config/initializers/devise.rb

从配置/ initializers / devise.rb的代码片段

# Configure the class responsible to send e-mails.
config.mailer = "Notifier"

我的通知程序邮件程序现在

class Notifier < Devise::Mailer
  # set some sensible defaults
  default :from => MyApp::Application.config.postmark_signature

  # send a receipt of the Member's purchase
  def receipt_message(order)
    @order = order
    @billing_address = order.convert_billing_address_to_hash(order.billing_address)

    mail(:to => @order.user.email, :subject => "Your Order Receipt", :tag => 'order-receipt', :content_type => "text/html") do |format|
      format.html
    end
  end

  # send password reset instructions
  def reset_password_instructions(user)
     @resource = user
     mail(:to => @resource.email, :subject => "Reset password instructions", :tag => 'password-reset', :content_type => "text/html") do |format|
       format.html { render "devise/mailer/reset_password_instructions" }
     end
   end
end


推荐答案

使用最新版本的Devise,上述方法没有帮助我。这是我的解决方案。

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

在config / application.rb中:

In config/application.rb:

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

在config / initializers / devise.rb: p>

In config/initializers/devise.rb:

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

在app / mailers / user_mailer.rb中:

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

并从app /视图/ devise / mailer / to app / views / user_mailer /

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

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

这篇关于如何自定义Devise发送密码重置邮件使用PostMark邮件程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆