POPing mails into Rails

There are countless ways of Getting Mails into a Ruby on Rails application. This is my take:

Running a Mailserver nowadays is a burden. So I like to outsource it. I get all mail to *@example.com delivered to a POP3 account. I use getmail to fetch the mail via POP3 and stuff it into ActionMailer. I also keep a kopy of each Mail in a so called maildir because I don’t trust this Web-Database-Thingies.

I have a dedicated user, let’s say called ‚project‘. So I created ~/.getmail/getmailrc:

[retriever]
type = MultidropPOP3Retriever
server = pop3.example.com
username = something
password = secret
envelope_recipient = x-envelope-to:1

[destination]
type = MultiDestination
destinations = ("[maildir]", "[rails]")

[maildir]
# keep local copies. Don't forget 
# mkdir ~/Maildir ~/Maildir/tmp ~Maildir/new ~Maildir/cur
type = Maildir
path = /usr/local/project/Maildir/

[rails]
type = MDA_external
path = /usr/bin/env
arguments = ("RAILS_ENV=production", 
 "sh", "-c", 
 "cd /usr/local/project/rails; /usr/local/bin/ruby 
 script/runner 'Incoming.receive(STDIN.read)'")

[options]
# delete mails on server
delete = On

The call to runner is somewhat fancy to ensure it gets the environment right.

With tis setup I can use ontime mailadresses ensuring that any reply to mails my application had sent out can be easily connected to the related data. So when sending a mail about issue 345 to customer 12 I use something like service-345-12@example.com. When the customer replies to that mail I can parse the adress and extract the imformation. No further reason to bother customers with tracking numbers and the like.

One comment on “POPing mails into Rails

  1. f3ex
    2009-03-09 at 09:18 #

    thanks

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s