Question

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 :).

Edit

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.

Was it helpful?

Solution

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.

OTHER TIPS

Well. The answer depends on where the list of user accounts for dovecot and postfix is stored on your server. I.e. where do dovecot and postfix retrieve user accounts from. I.e. dovecot and postfix do not maintain their own lists of user accounts, they just take some existing list. For example, several years ago I had configured dovecot and postfix so that they were taking list of user accounts (and respective e-mail addresses, storage paths, etc) from MySQL database. In such implementation it would be enough just to insert several records in that MySQL database for adding new email account.

I don't know how dovecot and postfix are configured on your server. Maybe they are just using system user accounts (then you need to add user account with useradd/adduser), maybe they retrieve user account list from LDAP (then you need to insert users into LDAP), or just from plain config file (then you need to edit config file).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top