• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

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