简体   繁体   English

在dovecot / postfix上从php脚本创建一个新的电子邮件帐户

[英]Create a new email account from php script on dovecot/postfix

I'd like to make a page to allow people to create new email accounts on a dovecot/postfix server (via imap). 我想创建一个页面,允许人们在dovecot / postfix服务器上创建新的电子邮件帐户(通过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 ...) 我见过的PHP函数imap_openimap_createmailbox ,但这些功能不创建帐户,只创建一个新的目录:/(你需要一个现有帐户的登录/密码才能使用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. 我不希望最终用户看到管理面板。

Well. 好。 The answer depends on where the list of user accounts for dovecot and postfix is stored on your server. 答案取决于dovecot和postfix的用户帐户列表存储在服务器上的位置。 Ie where do dovecot and postfix retrieve user accounts from. 即dovecot和postfix从哪里检索用户帐户。 Ie dovecot and postfix do not maintain their own lists of user accounts , they just take some existing list. 即dovecot和postfix 不维护自己的用户帐户列表 ,他们只需要一些现有的列表。 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 . 例如,几年前我已经配置了dovecot和postfix,以便他们从MySQL数据库中获取用户帐户列表(以及相应的电子邮件地址,存储路径等) In such implementation it would be enough just to insert several records in that MySQL database for adding new email account. 在这样的实现中,仅在该MySQL数据库中插入若干记录以添加新的电子邮件帐户就足够了。

I don't know how dovecot and postfix are configured on your server. 我不知道你的服务器上是如何配置dovecot和postfix的。 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). 也许他们只是使用系统用户帐户(然后你需要使用useradd / adduser添加用户帐户),也许他们从LDAP检索用户帐户列表(然后你需要将用户插入LDAP),或者只是从普通配置文件(然后你需要编辑配置文件)。

By default postfix & dovecot get their users from the system. 默认情况下, postfix和dovecot从系统中获取用户。 This is /etc/passwd on a UNIX/Linux box. 这是UNIX / Linux机器上的/etc/passwd

Managing this from a PHP script is possible, but not too pretty. 从PHP脚本管理这个是可能的,但不是太漂亮。

  • You can use posix_getpwnam to check if a username exists, and get information about this user. 您可以使用posix_getpwnam检查用户名是否存在,并获取有关此用户的信息。

  • Adding users is best done with useradd(8) on Linux. 添加用户最好在Linux上使用useradd(8) You will need to use exec() to launch this shell utility. 您将需要使用exec()来启动此shell实用程序。 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. 我建议的是将用户存储在SQL数据库中,例如PostgreSQL,MySQL或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. 这很容易设置,在PHP方面,您所要做的就是在数据库上添加/删除/更新行。 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 . 后缀页面上有一些关于这个主题的“HOWTO”, dovecot也是如此

Aa a final option, there's LDAP. Aa是最终选项,有LDAP。 LDAP is more complex, but arguably 'better' & more flexible. LDAP更复杂,但可以说“更好”,更灵活。 PHP has a LDAP interface. PHP有一个LDAP接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM