19

PostMarkAppを使用し、Rails gem ( postmark -rails、 postmark -gem、およびmail ) を利用して、システムのすべての電子メール通知を 1 つの傘の下で取得しようとしています。購入の領収書の送信を処理するメーラーを正常に作成しましたが、パスワードを忘れたという電子メールを受信できませんでした。私の開発ログは、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

消印を使用するマイ メーラー

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"

My 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
4

3 に答える 3

1

消印ヘッダーに「タグ」も指定する場合は、メーラーでこれを行う必要があります。

  # this override method is from Devise::Mailers::Helpers
  def headers_for(action)
    headers = {
      :subject        => translate(devise_mapping, action),
      :from           => mailer_sender(devise_mapping),
      :to             => resource.email,
      :template_path  => template_paths,
      :tag            => action.dasherize # specify the tag here
    }
    if resource.respond_to?(:headers_for)
      headers.merge!(resource.headers_for(action))
    end
    unless headers.key?(:reply_to)
      headers[:reply_to] = headers[:from]
    end
    headers
  end
于 2011-12-02T22:56:53.737 に答える
0

また、devise のビューを生成し、メーラーの適切な場所にメール テンプレートをコピーする必要がありました。このようなもの -

rails generate devise:views
cp app/views/devise/mailer/* app/views/notification_mailer/
于 2011-05-16T20:12:21.463 に答える