【问题标题】:How to access list of email accounts with cPanel API?如何使用 cPanel API 访问电子邮件帐户列表?
【发布时间】:2014-10-21 02:50:14
【问题描述】:

cPanel 是我们在服务器上安装的网络服务器管理应用程序。它有一个基于XML/JSONPHP API,我们希望使用它来访问数据,例如所有电子邮件帐户的列表。这个系统是huge,我在任何地方都找不到答案。有谁知道如何使用 cPanel API 列出电子邮件帐户?

编辑:我需要的函数是listpopswithdisk (docs here),它列出了给定域下的电子邮件帐户,但不知道如何调用此函数。

【问题讨论】:

    标签: php api cpanel


    【解决方案1】:

    我认为任何人都可以使用这个普通的 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";
    }
    }
    }
    }
    }
    ?>
    

    【讨论】:

    • 好主意,但这只有在您自己在自己的服务器上安装了 cPanel 时才有效(具有 root 访问权限)。在共享托管服务器上,这不起作用。
    • 是的,没错... :)
    • 哦,真的吗?浮出我的乐趣.. 伙计.. 我如何阅读共享邮件?我很确定我找到了一种方法,我正在研究直接从例如阅读~/mail/domain/accountame/cur/* 使用某种 php exec、node 或 curl/fopen。
    【解决方案2】:

    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

    【讨论】:

    • Afterlogic PHP API 将仅列出 Afterlogic db 中包含的那些帐户。它只是 cPanel 邮件帐户列表的一个子集。如果您的 cPanel 服务器上有 1000 个邮件帐户,并且用户曾经使用 Afterlogic 登录过其中的 100 个帐户,那么只有这 100 个帐户将被添加到 Afterlogic 数据库中。
    猜你喜欢
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2013-06-10
    • 2016-05-14
    • 2016-11-30
    • 2016-08-27
    • 1970-01-01
    • 2013-05-28
    相关资源
    最近更新 更多