Page 1 of 1

creating email accounts automatically

Posted: Mon Apr 05, 2010 3:45 pm
by shawngoldw
Hi, I'm currently developing a website for an organization and would like each member of the organization to have an email address with the sites domain. The members will all be stored in a mysql database with an external email address (ie gmail, hotmail) and the email address with the sites domain will merely forward to the members desired address.

I am not sure how to go about doing this and would appreciate any help. Let me know if there is any information that you would need in order to better answer my question.

Thanks,
Shawn

Re: creating email accounts automatically

Posted: Mon Apr 05, 2010 4:22 pm
by AbraCadaver
Hi Shawn, Shawn here!

This depends upon your mail server. It would need to have a command line utility that would allow you to add addresses which could in turn be called by your PHP script. In the case of qmail, you would create a directory for the user and a maildir directory and add a .qmail file with the forwarding address in it. Other mail servers have different ways.

Re: creating email accounts automatically

Posted: Tue Apr 06, 2010 9:07 am
by shawngoldw
Thank you, I have to talk to my friend who is hosting the site in order to find out what type of mail server is used. Is it possible that just calling a a cgi, perl, etc. script from php to edit the /etc/aliases file could work?

Re: creating email accounts automatically

Posted: Tue Apr 06, 2010 10:12 am
by AbraCadaver
shawngoldw wrote:Thank you, I have to talk to my friend who is hosting the site in order to find out what type of mail server is used. Is it possible that just calling a a cgi, perl, etc. script from php to edit the /etc/aliases file could work?
As far as I remember /etc/aliases is only for local accounts. If everything is working properly (you can receive mail) then it is very easy to edit whatever files you need using PHP. Your Apache/webserver user would need write permissions to those files of course.

Re: creating email accounts automatically

Posted: Tue Apr 06, 2010 2:43 pm
by shawngoldw
AbraCadaver wrote:As far as I remember /etc/aliases is only for local accounts.
Would you mind clarifying this statement for me? Do you mean that it can only forward to local accounts? or from local accounts? or do you need a local account to edit it?

Thanks

Re: creating email accounts automatically

Posted: Tue Apr 06, 2010 3:02 pm
by AbraCadaver
shawngoldw wrote:
AbraCadaver wrote:As far as I remember /etc/aliases is only for local accounts.
Would you mind clarifying this statement for me? Do you mean that it can only forward to local accounts? or from local accounts? or do you need a local account to edit it?

Thanks
As I remember it only forwards from a local account to a local account, like all mail to root forward to shawn. I may be wrong and this could work for your purpose, but I haven't done much mail configuration for a long time. If you can work out what file(s) need to change and what needs to go there, I can help with the PHP.

Re: creating email accounts automatically

Posted: Wed Apr 07, 2010 12:24 pm
by shawngoldw
I found this article explaining how to make a mailing list by only modifying the aliases file. It looks like if you have a local address you can just put the username and if it is not a local address you can put the whole address (ie shawn for local and shawn@domain.com for non local). Then you run a command called 'newaliases' to update aliases.db.

http://tldp.org/LDP/LG/issue72/teo.html

A little excerpt from the page, here is their example of what to add to the hosts file:
The first thing you need to do is to think of a name for your mailing list. For example, if the Linux box you're using is called mybox.example.com, you can call your mailing list address "theproject@mybox.example.com". Any e-mails sent to theproject@mybox.example.com will then be propagated to all e-mail addresses registered to it. For the purpose of this article, let's say we want the mails that reach that address to go out to linus@mybox.example.com, alan@example.net, and esr@example.org.

The next thing you need to do is to set up the MTA's aliases file. The aliases file is usually stored as /etc/aliases or /etc/mail/aliases depending on your Linux distribution. Once you locate it, fire up your favorite text editor and edit it. You may see some default lines in that file, such as "webmaster: root", "postmaster:root", and so on. Just ignore those lines and scroll to the end of the file. Now add the following lines:

# The Project mailing list
theproject:
linus,
alan@example.net,
esr@example.org

I have tested the function is_writable() on /etc/hosts and has returned false while is_readable returns true. So does this mean that if the aliases approach would work for my purpose I must call some other script from my php file, such as a perl script?

Thanks

Re: creating email accounts automatically

Posted: Wed Apr 07, 2010 12:35 pm
by AbraCadaver
Any script you call from PHP will be running as the web user, so you might as well edit this file with PHP. To do tis you'll have to change the permissions. This is possibly a security risk, but it's the only way you'll be able to edit the file from PHP.

Re: creating email accounts automatically

Posted: Wed Apr 07, 2010 1:33 pm
by shawngoldw
I would prefer not to edit permissions on that file. I think I'll use cron to edit the file.

Thanks for all the help