【问题标题】:How to create user on hMailServer programatically?如何以编程方式在 hMailServer 上创建用户?
【发布时间】:2015-07-15 13:41:10
【问题描述】:

我们正在编写一个专门的 PHP 电子邮件客户端,并希望该客户端的管理员能够在 hMailServer 上创建用户帐户。

我尝试了imap_createmailbox(...),但它只是在用户的文件夹结构中创建了一个目录,而不是我们想要的“为新用户创建邮箱”。

hMailServer 是否有某种接口,以便我可以启用我们的 PHP 电子邮件客户端通过代码创建 hMailServer 帐户?

【问题讨论】:

    标签: hmail-server


    【解决方案1】:

    是的,在 hmailserver 中创建帐户有两个接口。

    一、通过数据库,可以选择账号密码哈希类型(0,1,2,3)和签名等经典信息。由于同步原因,我不推荐这种方法,hmail-server 需要缓存时间来考虑数据库更新。

    两个,我推荐的是使用 API COM,它提供了所有流行语言的所有可能的方法。 您必须在 Windows 服务器中启用 D-COM。 APIguide

    【讨论】:

      【解决方案2】:

      hmailserver 版本:hMailServer 5.6.4 - Build 2283 c#中hmailserver创建新邮箱的完整解决方案 如果你已经成功配置了hmailserver,那么你可以使用以下步骤在c#中通过hmailserver创建新帐户

      1. hmailserver 连接

           private Domain HMailServerConnection() {
                var objGlobal = new ApplicationClass();
                   objGlobal.Authenticate(ConfigurationManager.AppSettings["HMailUsername"], ConfigurationManager.AppSettings["HMailPassword"]);
                return objGlobal.Domains.get_ItemByName(ConfigurationManager.AppSettings["hMailDomain"]);
            }
        
      2. 创建新电子邮件帐户的功能

        public string AddNewAccount(string email,string password)
        {
        try
        {
            Domain domain = HMailServerConnection();
            Accounts accounts = domain.Accounts;
            Account mailbox = accounts.Add();
            mailbox.Address = email;
            mailbox.Password = password;
            mailbox.Save();
            return "success";
        }
        catch(Exception ex)
        {
            return "error";
        }
        }
        
      3. App.config 或 web.config 中的应用设置

          <appSettings>
            <add key="hMailDomain" value="domainname"/>
            <add key="HMailUsername" value="Username"/>
            <add key="HMailPassword" value="password"/>
          </appSettings>
        

      link

      它的工作我测试了它。

      【讨论】:

        【解决方案3】:
        <?php   
        header('Content-Type: text/html; charset=utf-8');
        $obBaseApp = new COM("hMailServer.Application", NULL, CP_UTF8);
        $obBaseApp->Connect();
        
        $hmail_config['rooturl']            = "http://localhost/";      
        $obAccount = $obBaseApp->Authenticate("Administrator", "hMailserver Administrator 
        password");
        
        if (!isset($obAccount)) {
              echo "<b>Not authenticated or Administrator's password wrong</b>";
        } else {
        
        try {
            echo "<b>Logon COM [OK], now we can add accounts</b>";
        
            $obDomain   = $obBaseApp->Domains->ItemByDBID(1); 
            $obAccount = $obDomain->Accounts->ItemByDBID(1);  // account id
        
              $domainname = $obDomain->Name;
               $obAccounts = $obDomain->Accounts();       
               $obAccount = $obDomain->Accounts->Add();
               $newalias = "powerranger";
               $firstname = "Arnold";
               $lastname = "Schwarzenegger";
               $my_domainname ="@mydomain.com";
        
                 $obAccount->PersonFirstName = $firstname;
                 $obAccount->PersonLastName = $lastname;
                 $obAccount->MaxSize = 102; // 102 MB set inbox space
                 $obAccount->Address = $newalias .$my_domainname; 
                 $obAccount->Password = "secret"; // provide this in Thunderbird/Outlook ect.
                 $obAccount->Active = true; // set account to active
                 $obAccount->Save(); // save, finish.
        
             /* If we reaching this point, everything works as expected */
             echo "<br/><h3> Account was successfully created, now you can login with".
                              "an POP3 or IMAP-Client </h3>";
        
        } 
        /* OK, if something went wrong, give us the exact error details */  
        catch(Exception $e) {
            echo "<h4>COM-ERROR: <br />".$e->getMessage()."</h4><br />";        
        }
        

        }

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-07-30
          • 2017-11-29
          • 2018-06-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-16
          • 2020-08-06
          相关资源
          最近更新 更多