Email: Subdirectory/Mailbox Creation

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello Michael,

The following UAPI function is available for creating email accounts:

UAPI Functions - Email::add_pop - Software Development Kit - cPanel Documentation

The default directories associated with email accounts are created automatically once the email account is setup. As far as custom mail folders, there's no corresponding API function for that because custom email folders are created in the email or webmail client.

Thank you.
 

shashaa

Registered
Jun 30, 2022
1
0
1
Nigeria
cPanel Access Level
Website Owner
Hello Michael,

The following UAPI function is available for creating email accounts:

UAPI Functions - Email::add_pop - Software Development Kit - cPanel Documentation

The default directories associated with email accounts are created automatically once the email account is setup. As far as custom mail folders, there's no corresponding API function for that because custom email folders are created in the email or webmail client.

Thank you.
Hi CpanelMichael,

This is close to my question.

I Use Cpanel UAPI to control Cpanel, so far I have been able to

List domains, Show domain data, Add subdomain, List email account, create email account, delete email account, list database, create database and delete database.

Now I have an ISSUE, which is I am trying to create bulk email address ids for a domain automatically.

I use this in PHP

$parameters = [
'email' => newemail, //username
'password' => loremipsumodid, //password
'domain' => example.com, //domain
'quota' => 0,
];

$result = $cPanel->execute('uapi', "Email", "add_pop", $parameters);

if (!$result->status == 1) {
echo "Error";
} else {
echo "Email added";
}

to create a single email address, but what i want is to be able to create a lot of email id.

I do not see anything on this Email Accounts of Cpanel UAPI documentation

I have called all my emails from database into an array, which I use array map to read, but I can't seem to be able to add multiple email addresses at once to Cpanel.

I want to be able to add [email protected], [email protected]. [email protected]. [email protected].

I get:

Notice
: Undefined variable: cPanel in C:\xampp\htdocs\auth\ajax.php on line 525

Fatal error
: Uncaught Error: Call to a member function execute() on null in C:\xampp\htdocs\auth\ajax.php:525 Stack trace: #0 C:\xampp\htdocs\auth\ajax.php(658): (Array) #1 [internal function]: {closure}('[email protected]...', 'd%sxy$d3}2*uo32...', 'encrypted') #2 C:\xampp\htdocs\auth\ajax.php(673): array_map(Object(Closure), Array, Array, Array) #3 {main} thrown in C:\xampp\htdocs\auth\ajax.php on line 525

When I do this

$marray_three = ALL EMAIL USERNAMES TO ADD

$marray_two = ALL CORRESPONDING PASSWORDS

$marray_four = DOMAIN TO USE eg example.com

array_map(function ($marray_three, $marray_two,$marray_four) {

$marray_three;
$marray_two;
$marray_four;

$email_quota = "0";
$parameters = [
'email' => $marray_three , //username
'password' => $marray_two, //password
'domain' => $marray_four, //domain
'quota' => $email_quota,
];


$result = $cPanel->execute('uapi', "Email", "add_pop", $parameters);


}, $marray_three, $marray_two,$marray_four);

to try to add an array list of email addresses from database but I keep getting the error above.

What am I doing wrong.
 
Last edited:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
11,783
1,872
363
cPanel Access Level
Root Administrator
I can't really comment on the PHP side of things as I don't speak PHP and I'm not a developer. When I work with the API I usually try and ensure the basic commands work directly on the command line before adding them to any additional tools. For this work, I'd be included to use a for loop along with the API call from the command line to iterate through a list of addresses.