通过继承Devise :: Mailer来定制Mailer

时间:2014-02-27 23:19:53

标签: devise mailer

我在Github上找到了关于如何从Devise创建自定义邮件程序的精彩教程。 https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer

我实现了代码并且逻辑对我来说完全合理,但是当我部署时,当我在initialize / devise.rb中设置config.mailer ='MyMailer'时,我无法使代码工作。终端中没有错误,似乎所有内容都像正常一样处理,但电子邮件从未进入收件箱。

如果我更改config.mailer ='Devise :: Mailer',电子邮件将正确发送。但是,由于MyMailer继承自Devise :: Mailer,它应该不起作用吗?

还有其他人有这个问题吗?我有什么想法可以排除故障吗?

这是我的“mailers / my_mailer.rb”:

class MyMailer < Devise::Mailer
  helper :application # gives access to all helpers defined within `application_helper`.   
  # helper :devise # gives access to all helpers defined within `devise_helper`.
  #include Devise::Controllers # Optional. eg. `confirmation_url`
  include Devise::Mailers::Helpers

  def invoice_payment_failed_email(user, listing)
    @user = user
    @listing = listing
    @url  = 'http://example.com/login'
    mail(to: @user.email, subject: 'Payment Failed')
  end
end

这是我的“initializers / devise.rb”:

Devise.setup do |config|
  config.secret_key = ENV["DEVISE_SECRET_KEY"]

  # Configure the class responsible to send e-mails.
  config.mailer = 'MyMailer'

以下是我发送邮件的电话:

# email customer
MyMailer.invoice_payment_failed_email(@user, @listing).deliver

*更新: OMG ...在经过一整天的努力试图解决这个问题后,事实证明代码逻辑很好,但问题是我的From:需要匹配Postmark发件人帐户。这就是我没有收到任何终端错误的原因。发送请求正在正确发送到邮戳,但由于我的发件人地址不匹配,邮戳只是从未发送过电子邮件!

0 个答案:

没有答案