I changed some code in the ISPcfg3 module because I have multiserver setup with multiple mail servers and I wanted to add mail server for a new user to the server with the least amount of mailboxes in the hope of load balancing my mail servers like I do now with the web servers. I simply lifted the code from cwispy's latest addon and modified it to count mailboxes on each mailserver instead of websites. PHP: if (count( $server['mail_server'] ) == 1 ) { $defaultmailserver = $server['mail_server'][0]['server_id']; } else { /* $rnd = rand(0, ( count( $server['mail_server'] ) - 1 ) ); $defaultmailserver = $server['mail_server'][$rnd]['server_id']; */ /* Andy added this to choose mail server with least amount of mail accounts */ $a = 1; $b = 0; while ( $a <= count($server['mail_server']) ) { $result = array(); $result = $client->mail_user_get( $session_id, array( 'server_id' => $server['mail_server'][$b]['server_id'], 'homedir' => '/var/vmail') ); if (!isset($mailboxcnt)) { $mailboxcnt = count( array_keys($result) ); } if ( $mailboxcnt > count( array_keys($result) ) OR ( !isset($defaultmailserver) ) ) { $mailboxcnt = count( array_keys($result) ); $defaultmailserver = $server['mail_server'][$b]['server_id']; } $a++; $b++; } unset($a); unset($b); }