【发布时间】:2014-10-21 02:50:14
【问题描述】:
cPanel 是我们在服务器上安装的网络服务器管理应用程序。它有一个基于XML/JSON 的PHP API,我们希望使用它来访问数据,例如所有电子邮件帐户的列表。这个系统是huge,我在任何地方都找不到答案。有谁知道如何使用 cPanel API 列出电子邮件帐户?
编辑:我需要的函数是listpopswithdisk (docs here),它列出了给定域下的电子邮件帐户,但不知道如何调用此函数。
【问题讨论】:
cPanel 是我们在服务器上安装的网络服务器管理应用程序。它有一个基于XML/JSON 的PHP API,我们希望使用它来访问数据,例如所有电子邮件帐户的列表。这个系统是huge,我在任何地方都找不到答案。有谁知道如何使用 cPanel API 列出电子邮件帐户?
编辑:我需要的函数是listpopswithdisk (docs here),它列出了给定域下的电子邮件帐户,但不知道如何调用此函数。
【问题讨论】:
我认为任何人都可以使用这个普通的 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";
}
}
}
}
}
?>
【讨论】:
~/mail/domain/accountame/cur/* 使用某种 php exec、node 或 curl/fopen。
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
【讨论】: