• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue API for email alias

Geraldo V Vieira

New Pleskian
Hi

I'm doing this addon for Roundcube to be able to view/add/delete email alias but I'm a little stuck. The example below has 5 email alias but its only showing the first alias. Does anyone know how I can get it to display all of the aliases?

Code:
$plek_email = <<<EOF
<packet>
    <mail>
        <get_info>
            <filter>
          <site-id>$plesk_client_domain</site-id>
        </filter>
            <mailbox/>
            <aliases/>
        </get_info>
    </mail>
</packet>
EOF;
        $plesk_email_response = new SimpleXMLElement($plesk_client->request($plek_email));
        $plesk_client_email = [];
        foreach($plesk_email_response->mail->get_info->result->mailname as $mailname) {
            $plesk_client_email = [
                'id' => $mailname->id,
                'name' => $mailname->name,
                'alias' => $mailname->alias,
            ];
        }
 
Last edited:
I'm getting just the word "admin" which is the first email alias for that email address. For example, the email address is [email protected] and it has 4 email alias attached to it witch are admin, shopping, help and contact. The XML response is only showing admin and it isn't show the other 3.
 
I'm using "new SimpleXMLElement" so there's no XML output part from single values. It's literally only outputting the words "admin" which is the first alias. The Full XML without using "new SimpleXMLElement" is as follows:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.9.1">
<mail>
<get_info>
<result>
<status>ok</status>
<mailname>
<id>6</id>
<name>info</name>
<mailbox>
<enabled>true</enabled>
<quota>-1</quota>
</mailbox>
<alias>admin</alias>
<alias>shopping</alias>
<alias>help</alias>
<alias>contact</alias>
<user-guid>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</user-guid>
<antivir>inout</antivir>
<description/>
</mailname>
</result>
</get_info>
</mail>
</packet>
 
It is as simple as looping trough the XML <alias> element. As you can see from your XML output, the aliases are present in the result.
XML:
<alias>admin</alias>
<alias>shopping</alias>
<alias>help</alias>
<alias>contact</alias>

A loop like this works to get all aliases
PHP:
foreach($response->mail->get_info->result->mailname->alias as $alias) {
      print_r($alias);
}

Pro tip: there is an PHP library/wrapper for the Plesk XML-RPC API available on Github. It is by no means compleet and does not contain any methodes for mail aliases. However the library is a great tool to get started with the Plesk XML-RPC API for any PHP project and can easily be expanded to fit you own needs. Makes your (developer) life a bit easier :)
 
Last edited:
Back
Top