views:

92

answers:

4

I've seen on site like flickr or brightkite, a personnal email is provided to the users. If the user mail somethin to this adresse, the content is posted on his public profile. How can I do that on a web application ?

+4  A: 

There are two ways to do this, as I see it:

First, you can use an existing SMTP server/email box system and, on an interval, pull the messages from that mail box using POP3 or IMAP to insert stuff into your database/system.

Alternatively, you can write an implementation of SMTP that will accept email messages coming in and perform your custom logic to put data into your database/system instead of into a mailbox. This is, ultimately, a cleaner design that will have much less overhead. In fact, there may be an SMTP server implementation out there somewhere already that will allow you to inject this kind of custom logic (I'll edit if I can find one).

Personally, I'd go with the second option. This will give you much more control over what's going on in your system and it will have an overall cleaner design.

Good luck!

Edit: It's not PHP, but JAMES from Apache is a Java mail server that allows you to inject custom mail processing units (called mailets) to handle mail processing. You could write such a mailet that will process email messages and put the updates in your database instead of a mailbox. There may be other projects that implement this kind of design, so it's worth a look.

Edit again: Ooo... here's an open source php SMTP server on SourceForge. I don't know that you can inject custom logic, but you can always edit the source and make it do what you want! (If you insist on PHP anyway)

dustyburwell
awesome, thank you for your edit about the "mailets" :)
mdcarter
I also added a link to an open source php SMTP server, if you're interested in that.
dustyburwell
+1  A: 

There are several free mail servers available that support using MySQL or any other database as a storage backend and requires only configuration to do so. If you're not comfortable customizing an existing mail server or writing your own, I'd go with that solution. It's several orders of magnitude faster than using POP3 or IMAP to communicate with the mail server.

Emil H
do you have some name? i'm not very familiar with mail server functionnement :s
mdcarter
A: 

Flickr has published their methods for doing exactly this in the book Building Scalable Websites. The whole of chapter 6 is dedicated to the topic. You don't need a non-standard MTA, as mentioned above. The default MTAs will work fine (sendmail, qmail, postfix, exim, etc.). All you have to do is edit /etc/aliases. /etc/aliases can be used to set a mailbox to pass all email to a script.

I strongly recommend reading through this chapter, as it goes on to outline a lot of the common issues you'll run into doing exactly this -- parsing attachments, coping with email from mobile devices (which frequently includes bad/quirky headers), doing authorization correctly, etc.

Frank Farmer