How to receive email via IMAP protocol in Rails 3
What is the best way to receive email vi开发者_运维技巧a IMAP protocol in Rails 3?
I am not sure about best, but a simple way is to use Net::IMAP
. You can write a rake
task and periodically poll the mailbox for emails by using a scheduler like cron
.
So your setup would look like this:
- A library file which servers as a wrapper for
IMAP
client and other related operations, like processing the emails. - The
rake
task which when called downloads the emails and processes them using the wrapper mentioned above. - The scheduler (Cron or any other of your choice. I personally always prefer
cron
) which periodically calls thisrake
task.
As per ActionMailer
's documentation the solution is to have the email forwarded to your rails application and implement UserMailer.receive(STDIN.read)
to process the email.
The documentation (Action Mailer Basics) doesn't sound very convincing about this approach. It's not telling where the call should be implemented but I guess that would be at the MTA level.
精彩评论