I would like to know if it is possible to create an email account using CPANEL, but not in a manual way, but in a programmatic way?
I need to automate the creation, because manually it would not be possible to deal with the demand.
I would like to know if it is possible to create an email account using CPANEL, but not in a manual way, but in a programmatic way?
I need to automate the creation, because manually it would not be possible to deal with the demand.
The CPanel documentation guides you to use the UAPI: link
Supported version: 11.42 or higher
To create an email account, I'll show you an example with LiveAPI (PHP Class)
// Inclua a library principal do CPANEL
// O local do arquivo varia de acordo com o ambiente. Verifique em qual local está o arquivo no seu ambiente.
require_once '/usr/local/cpanel/php/cpanel.php';
// Instancia o objeto CPANEL. (Faça apenas uma instância)
$cpanel = new CPANEL();
// Aqui invocamos o método uapi informando os parâmetros para criação de conta de email
// Criaremos o email [email protected] com 50mb de quota (espaço limite em disco)
$new_email = $cpanel->uapi(
'Email', 'add_pop',
array(
'email' => 'sample',
'password' => '123456',
'quota' => '50', // Caso queira ilimitado, coloque 0 (ZERO)
'domain' => 'foo.bar', // domínio
'skip_update_db' => '1'
)
);
Successfully returns a string in user+domain
format. In the case of the above example, sample+foo.bar
.
Documentation: link
For version 11 to the current version (legacy): link
// Create the [email protected] email address.
$add_email_address = $cpanel->api2(
'Email', 'addpop',
array(
'domain' => 'foo.bar',
'email' => 'sample',
'password' => '123456',
'quota' => '50',
)
);