I'd like to make a page to allow people to create new email accounts on a dovecot/postfix server (via imap).
I've seen the php functions imap_open
and imap_createmailbox
, but these functions don't create accounts, it only creates a new directory :/
(and you need the login/password of an existing account to use imap_open
...)
So I'd like to know if it's possible to do this :).
I'm adding this because my previous message wasn't specific enough. I need a front page to allow the users to register a new mailbox and to check if their wanted mail alias is free or not. That's why most of the web-based admin are not good for me. I don't want the end-users to see the admin panel.
By default postfix & dovecot get their users from the system. This is /etc/passwd
on a UNIX/Linux box.
Managing this from a PHP script is possible, but not too pretty.
You can use posix_getpwnam
to check if a username exists, and get information about this user.
Adding users is best done with useradd(8)
on Linux. You will need to use exec()
to launch this shell utility. Example usage might be:
$pw = crypt($_POST['password'], '$6$1234567890123456'); # This should be 16 characters of random salt
exec(sprintf('useradd --groups mailuser --no-user-group --shell nologin --password %s', escapeshellarg($pw));
I wouldn't really recommend this, though.
What I would recommend, is storing your users in a SQL database, such as PostgreSQL, MySQL, or SQLite. This is fairly easy to set up, and on the PHP side all you have to do is add/remove/update rows on the database. This is probably the best solution since it's not too complex, yet still fairly flexible.
The postfix page has a few "HOWTO's" on the subject, and so does dovecot.
Aa a final option, there's LDAP. LDAP is more complex, but arguably 'better' & more flexible. PHP has a LDAP interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With