• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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