0

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

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

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

4

3 回答 3

1

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

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

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

于 2015-07-15T23:39:08.383 回答
0

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

  1. 邮件服务器连接

       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>
    

链接

它的工作我测试了它。

于 2015-12-17T04:51:40.037 回答
0
<?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 />";        
}

}

于 2019-07-20T10:40:51.960 回答