Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practices for receiving email in rails

I've been trying to figure out the best way to handle incoming email in a rails applications. I realize "best practices" is quite subjective, so I'll start by stating that my primary concerns are scalability and efficiency. This is an issue primarily because my use will involve handling potentially large attachments.

Seems like just yesterday the accepted method was to use ActionMailer to receive the email, but recently I've stumbled across several articles saying this is inefficient as it spawns a new rails instance with each email (horrible at high volumes).

Most recently, this article has been getting my attention: http://jasonseifer.com/2009/04/24/receving-email-with-rails

The post talks about a slimmed down version of the ActionMailer system that isn't forced to spawn an entire rails instance, but the comments talk about several other options like a dedicated mail directory (maildir?) and imap/pop retrieval.

My question is: Does anyone have any thoughts on what the best option would currently be for processing incoming email in a rails application (including attachments)?

like image 302
Ryan Avatar asked Aug 16 '09 03:08

Ryan


2 Answers

I maintain the Fetcher plugin for download email from an IMAP server which I use with cron. I used to use a daemon but that was tough to keep running (even with monit) because Ruby would hang. Cron is OK for my workload but it does spawn a Rails process once a minute.

For processing attachments, check out the MMS2R library. It has a nice interface for getting the files out of an email.

The other approach I've had recommended to me is to fire off an HTTP post for each message received. Then you can scale your web tier to handle it.

Shameless plug: you may want to check out Mike Mondragon and my PeepCode book on receiving email with Ruby.

like image 52
Luke Francl Avatar answered Nov 04 '22 18:11

Luke Francl


You could try to use a service like http://cloudmailin.com/

like image 26
MatthewFord Avatar answered Nov 04 '22 18:11

MatthewFord