tags:

views:

95

answers:

2

Remember iwantsandy.com? It was quite popular for what it did. ANyways, I'm looking to do something similar, but my question is, how does one process incoming emails? Let's assuming I'm using PHP or maybe even Ruby to do this. I would need a way to process the emails and dump them into a DB or something. Ok fine, but my main question is getting a script to kick off when an email comes in.

I have a VPS so I have full control over my environment and it's running Centos.

+5  A: 

Set up a pipe alias which forwards the message to the stdin of a script:

/etc/aliases:

sendmailhere:    |/usr/local/bin/myscript
Ignacio Vazquez-Abrams
and you may need to run the `newaliases` command
gnibbler
How do some of the companies like FB and other sites do it? You know the ones where you can send a picture directly to an email address that's associated with your account. Imagine at any given time hundreds if not thousands are sending such emails. Would a script be able to handle that?
luckytaxi
The MTA queues incoming messages until the script is ready to process them.
Ignacio Vazquez-Abrams
+1  A: 

For this project I would use a PHP email client such as IMAP for PHP. I would have a cron job to execute the PHP script every ~10min. It will pull down all messages in the inbox and reply as needed.

Rook