• Debian 11 is approaching its end-of-life (vendor EOL date - August 31, 2026). Plesk Obsidian 18.0.80 will be the last release to support it.
    If you are running Plesk Obsidian on Debian 11, we recommend you upgrade those servers to Debian 12 using our dist-upgrade tool.
  • We plan to deprecate and remove the support for XML RPC protocol versions earlier than 1.6.9.1 in Plesk Obsidian 18.0.82. We strongly recommend that you update all existing integrations using earlier versions of the XML RPC protocol to comply with the version 1.6.9.1 specification.

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