cPanel是我们在服务器上安装的Web服务器管理应用程序。它有一个基于XML/JSON的PHP API,我们希望用它来访问所有电子邮件帐户列表等数据。这个系统是huge,我无法在任何地方找到答案。有谁知道如何使用cPanel API列出电子邮件帐户?
修改:我需要的功能是listpopswithdisk
(docs here),它列出了给定域下的电子邮件帐户,但不知道如何调用此功能。
答案 0 :(得分:3)
我认为任何人都可以使用这个普通的PHP脚本获取他/她的网站cPanel电子邮件帐户。 我正在使用这个脚本进行个人工作,并且工作正常。
<?php
$domain = 'domain';
$username = 'username';
$quota = 'default_quota';
$mails = "/home/".$username."/.cpanel/email_accounts.yaml";
$mail_info = file_get_contents($mails);
$get_domain_mails = explode('account_count:',$mail_info);
foreach ($get_domain_mails as $accounts_email)
{
$acc = explode(' ',$accounts_email);
$m = $acc[1];
$clean = str_replace($m,"",$accounts_email);
$get_data = str_replace("accounts:","",$clean);
$exp_ag = explode("'",$get_data);
foreach ($exp_ag as $brk)
{
$ex = explode("diskquota",$brk);
foreach ($ex as $na)
{
$aex = explode('disk_mtime',$na);
$aarx = explode("diskused",$aex[0]);
foreach ($aarx as $tax)
{
$rexp = explode(":",$tax);
$reaexp = str_replace(" ","",$rexp[1]);
if ($reaexp!="")
{
$lex = explode($quota,$reaexp);
$naex = explode("\n",$lex[0]);
echo $naex[1]."\n";
}
}
}
}
}
?>
答案 1 :(得分:0)
cpanel UAPI listpops应该可以解决问题
UAPI Functions - Email::list_pops
由于您标记了PHP,因此继承了PHP示例
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.
// List all email addresses that contain "user".
$emails = $cpanel->uapi(
'Email', 'list_pops',
array(
'regex' => 'user',
)
);
参考https://documentation.cpanel.net/display/SDK/UAPI+Functions+-+Email%3A%3Alist_pops
另外看看Afterlogic的WebMail Lite API,它有很多功能,包括PHP和JS,以及REST API。
REST API声明
GET /account/list
Returns list of users.
Required parameters:
* string token - token
Optional parameters:
* int page - page number of the list. Default value: 1
* int usersPerPage - number of users per page. Default value: 100
* string orderBy - sorting field. Accepted values: email / name / last login
* string searchDesc - search string used for looking up specific account
* string domain - domain
Return: array
Sample request:
http://yourdomain/rest.php/account/list?token=yourToken
curl -X GET -d "token=yourToken" http://yourdomain/rest.php/account/list
Sample response:
"result":
[
{
"Id": 32,
"Email": "yourName@yourdomain.com",
"FriendlyName": "Name"
},
{
"Id": 33,
"Email": "yourOtherName@yourotherdomain.com",
"FriendlyName": "OtherName"
}
]
http://www.afterlogic.org/docs/webmail-lite/integration-and-development/rest-api#get-/account/list