views:

319

answers:

2

First, this question is assuming that there is a working method for interacting with a Mail Server in this fashion. If it's not, please feel free to let me know. Second, I'm relatively new to working with Mail Servers, so any related reading materials would be greatly appreciated.


I'm working on a project that allows the creation of online stores using top-level domains. The solution is rather robust and I'm happy with how it's come out. However, the need has come to allow users who use top-level domain names for their stores to also host their email with us. The solution has a built in messaging center that I'd like to utilize, which is currently using MySQL for message storage (similar to the messaging systems on various social networking sites). I've been reading on working with POP in PHP, and integrating in that way shouldn't be an issue. However, I'm running into a wall when it comes to the actual mail account creation and management, as there seems to be little to no accessible (on the web) learning material on the subject.

In my ideal situation, upon a new user registration, I'd like to use the username and password that they've chosen as their account access credentials to setup a default user on the mail-server, and provide an interface within the solution to add, remove, and modify users on the mail server, which I would then access via a POP mail application/interface.

Here's what I'm working with: I'm hosting with MT, running QMail, PHP 5.2, MySQL 4, and Apache on a Linux server. I have shell access (root), and can modify any necessary root files. Also, I'm allowing users to point domains to their stores via A-Records as well as by NS records. I'm assuming that I'll need to ask them to point their domain's MX records to my mail-server address in order for this to work?

What I'm looking for is a place to start looking and learning. Reading materials, tutorials, case-studies, etc. Whatever you can send over to help me get closer to my goal. Also, if the method I've described above is flawed, or you can recommend a better method, I'd be willing to hear your thoughts on that as well.

Feel free to use this thread as an open discussion on the topic as well (though, I'd like answers and suggestions to be a first priority).

Thanks! :)

A: 

You can setup your Email server to deliver email messages into a PHP script, and then reading the messages from the input stream (php://stdin). This way you don't have to manage actual mail accounts per user, but have your script logic handle it based on the prefix of the email address (the part before the @).

See an example of how to set this up - here.

Eran Galperin
Thanks! :) That's a great answer, and a method I hadn't considered. I'll look into it. However, is there no way to interact directly with the mail server via php? (that would be my ideal solution)
Lorren Biffin
There is, however it is neither simple nor recommended. By keeping the accounts virtual you have much more control over the logic of handling the messages than going through the trouble of dealing with mailboxes, accounts and so forth.
Eran Galperin
A: 

You need to create an email user in qmail. qmail is the pop server. I would not recommend trying to write your own. There is a lot of subtlety in RFC 2449 (http://www.faqs.org/rfcs/rfc2449.html).

There is a nice tutorial here for adding a new POP user to qmail. http://www.whirlycott.com/phil/pop3.html

You might want to write the user creation scripts in a wrapped shell script, then call from php. The process will need to be root

Once this is done, you can freely interact with the pop server using php pop libs.

For example, if you wanted to give the users webmail, you'd let them login, query the pop3 account as if you were a local email client (maybe writing to the database to store already read messages), and display their mail. http://librenix.com/?inode=1223

You will need to point the MX records to your mailserver, or the email will not be delivered.

You should also read the docs on qmail, I know, they are dense, but qmail does whole lot more than you'd first think.

Byron Whitlock
Awesome answer. Thanks! :)
Lorren Biffin