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.
thanks