views:

183

answers:

4

Hello all,

We would like to implement a feature by which users could send an email to an application specific address and we will parse the message and take certain actions on it, similar to 37signals's backpack (and probably some of their other apps).

If anyone has done something similar, could you fill me in on how you did so? I'm unsure on how to, at a high-level, 'import' the email into the app so that I could process it.

Thank you.

A: 

Why not run a Ruby SMTP mailserver, which will receive the mails via port 25, and then you can parse/interpret etc. as you wish ?

(I say Ruby since that's how you've tagged your question)

An alternative solution is to run procmail (or similar), pattern match on the subject, and then invoke scripts (configured in the .procmailrc file). However that may not scale so well for large volumes of mail.

Brian Agnew
A: 

ActionMailer can receive e-mails as well as send them! I don't remember how this is done but if you look at the documentation you can see it there. But from memory the e-mail gets piped through procmail into a script in the script directory.

There seems to be a book on the subject as well.

Good luck! :)

ba
+1  A: 

Here's how I fetch from a POP server:

require 'net/pop'

pop = Net::POP3.new('mail.yourdomain.com')
pop.start(account, password)
pop.each_mail do |m|
  email = TMail::Mail.parse(m.pop)
  email.base64_decode
  OttoMailer.process_email_in(email, m.unique_id)
  m.delete
end 
pop.finish
A: 

I have recently implemented that exact functionality in rails. I would advice you to look at the 'Receive E-mail Reliably via POP or IMAP' in the the Advanced Rails Recipes book.

I've personally found that the best source for getting this up and running and it explains how to do far better than I can. Good luck which ever way you choose to do it :)

tsdbrown
After looking into whether running a mail server or just using a plugin (fetcher) to fetch emails, import them, and process, I've decided that the latter is the best approach for me.Thanks for the responses all.
46and2