0

We are writing a specialized PHP e-mail client and would like to give administrators of this client the ability to create user accounts on hMailServer.

I tried out imap_createmailbox(...) but it just creates a directory in the user's folder structure but does not "create a mailbox for a new user" as we want.

Is there some kind of interface that hMailServer has so that I can enable our PHP e-mail client to create hMailServer accounts via code?

Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047

3 Answers3

1

Yes there two interfaces to create accounts in hmailserver.

One, via database, you can choose account and password hash type (0,1,2,3) and signature and other classic informations. I don't recommend this method for synchronisation reason, hmail-server take a caching time to consider the database update.

Two, which i recommend is to use API COM, its offers all possible methods in all cummon languages. You have to enable D-COM in your windows server. The API guide

Kassav'
  • 1,130
  • 9
  • 29
0

hmailserver version: hMailServer 5.6.4 - Build 2283 complete solution of create new email account by hmailserver in c# if you have configured hmailserver successfully, so then you can use the following steps to create new account by hmailserver in c#

  1. hmailserver connection

       private Domain HMailServerConnection() {
            var objGlobal = new ApplicationClass();
               objGlobal.Authenticate(ConfigurationManager.AppSettings["HMailUsername"], ConfigurationManager.AppSettings["HMailPassword"]);
            return objGlobal.Domains.get_ItemByName(ConfigurationManager.AppSettings["hMailDomain"]);
        }
    
  2. function to create new email account

    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 settings in App.config or web.config

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

see the link

its working i tested it.

adnan
  • 1,429
  • 1
  • 16
  • 26
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 />";        
}

}

Dravion
  • 36
  • 1