我试图使用PostMarkApp和Rails的gem(postmark-rails,postmark-gem,和mail)来将所有系统的电子邮件通知集中到一个地方。我已经成功创建了一个处理发送购买收据的邮件程序,但是我无法接收到忘记密码的电子邮件。我的开发日志显示Devise发送了消息,但是我没有在收件箱中收到任何邮件,而且PostMark的信用额度也没有减少。
最好或最简单的方法是什么,以便让Devise的邮件程序通过我的PostMark帐户发送邮件?
从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
使用 Postmark 的邮件发送器
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
编辑:以下是我的问题的解决方案
通过让我的Notifier
邮件处理器扩展Devise::Mailer并指定Devise使用我的Notifier作为邮件处理器,在config/initializers/devise.rb
中指定:
来自config/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