レールのメーラーデーモンにデータを渡しますか?
-
20-09-2019 - |
質問
Rails API(以下のスニペット)によると、メールを受信する最適な方法は、新しいメールが到着するたびにMTAによって呼び出されるデーモン内に単一のRailsインスタンスを作成することです。
私の質問は、新しいメールが到着したときにそのデーモンにどのようにデータを渡すのですか?
========================
Rails APIスニペット
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.
解決
あなたが提供する例では、電子メールを処理するために実行されるデーモンはありません。ドキュメントでは、この場合、メーラーデーモン、ポストフィックス、メールが受信されたときにコマンドを呼び出すことができると述べています。メーラーからコマンドを呼び出すとき:
rails_root/script/runner 'mailman.receive(stdin.read)'
電子メールのコンテンツは受信方法に渡されます。受信電子メールの処理を処理するより良い方法は、電子メールを受信する実際のメールボックスを作成することです。その後、バッチがメールボックスをチェックして電子メールを処理するRubyスクリプトを書くことができます。このタスクを実行するプロセスが1つしかないことを保証するために、ロックを実行してCronを介してそのスクリプトを呼び出すことができます。
所属していません StackOverflow