0

Rails API(以下のスニペット)によると、メールを受信する最適な方法は、新しいメールが到着するたびにMTAによって呼び出されるデーモン内に単一のRailsインスタンスを作成することです。

私の質問は、新着メールが到着したときに、どのようにしてそのデーモンにデータを渡すのかということです。

========================

RailsAPIスニペット

To receive emails, you need to implement a public instance method called receive that takes a tmail object as its single parameter. The Action Mailer framework has a corresponding class method, which is also called receive, that accepts a raw, unprocessed email as a string, which it then turns into the tmail object and calls the receive instance method.

Example:

  class Mailman < ActionMailer::Base
    def receive(email)
      page = Page.find_by_address(email.to.first)
      page.emails.create(
        :subject => email.subject, :body => email.body
      )

      if email.has_attachments?
        for attachment in email.attachments
          page.attachments.create({
            :file => attachment, :description => email.subject
          })
        end
      end
    end
  end

This Mailman can be the target for Postfix or other MTAs. In Rails, you would use the runner in the trivial case like this:

  ./script/runner 'Mailman.receive(STDIN.read)'

However, invoking Rails in the runner for each mail to be received is very resource intensive. A single instance of Rails should be run within a daemon if it is going to be utilized to process more than just a limited number of email. 
4

1 に答える 1

0

提供する例では、電子メールを処理するために実行されているデーモンはありません。ドキュメントには、メールを受信したときにコマンドを呼び出すようにメーラーデーモン(この場合はPostfix)を設定できると書かれています。メーラーからコマンドを呼び出す場合:

RAILS_ROOT / script / runner'Mailman.receive(STDIN.read)'

電子メールの内容は、receiveメソッドに渡されます。受信メールの処理を処理するためのはるかに優れた方法は、メールを受信する実際のメールボックスを作成することです。次に、メールボックスをバッチチェックして電子メールを処理するRubyスクリプトを記述できます。このタスクを実行するプロセスが1つだけであることを保証するために、そのスクリプトをcron経由で呼び出してロックを実行することができます。

于 2010-01-18T18:05:10.007 に答える