• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • 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.

Question Create Mailbox with PHP Script

airman1985

New Pleskian
Is it possible at all to create some sort of PHP Script for people so they can create Email Accounts on my Plesk?

Or the only way is to add manually being plesk admin.

Many thanks

Mark
 
Hi it is very complicated, however I downloaded a PHP examples and uploaded it to my server, then I modified the example.php file and I tried to run it but it had no effect. I am unsure how to determine the SITE ID and whether I need to modify the <packet> </packet> section.

Guru, please, can you have a look and help me modify this in order to add ONE email account at domain itskynet.uk?

#!/usr/bin/env php
<?php
// Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved.

require_once('PleskApiClient.php');

$host = getenv('itskynet.uk');
$login = getenv('admin') ?: 'admin';
$password = getenv('xxx');

$client = new PleskApiClient($host);
$client->setCredentials($login, $password);

$request = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<packet>
<mail>
<create>
<filter>
<site-id>1</site-id>
<mailname>
<name>techdept11</name>
<mailbox>
<enabled>true</enabled>
<quota>1024000</quota>
</mailbox>
<forwarding>
<enabled>true</enabled>
<address>[email protected]</address>
</forwarding>
<alias>michael555</alias>
<autoresponder>
<enabled>true</enabled>
<subject>Your request is accepted</subject>
<content_type>text/html</content_type>
<charset>UTF-8</charset>
<text>Your request will be processed in the nearest 10 days. Thank you.</text>
<attachment>
<tmp-name>/tmp/attachment-file.txt</tmp-name>
<file-name>rules.txt</file-name>
</attachment>
<forward>[email protected]</forward>
</autoresponder>
<password>
<value>test123</value>
<type>plain</type>
</password>
<antivir>inout</antivir>
</mailname>
<mailname>
<name>admin11</name>
<password>
<value>test</value>
</password>
<antivir>inout</antivir>
</mailname>
</filter>
</create>
</mail>
</packet>
EOF;

$response = $client->request($request);
echo $response;
 
site_id you can find in CLI with help of command

# plesk db -e "select id from domains where name='itskynet.uk'"

and make sure that you have specified correct admin's password here in the script:

$password = getenv('xxx');
 
@airman1985: Make sure that you run your script outside a subscription. Else you cannot access the necessary system file locations. In other words: Users from within a subscription will probably not be able to create a new mailbox through a website. When you grant all privileges that are required for that, make sure that the users cannot upload their own scripts into that subscription, because such scripts will then be able to access security sensitive areas of your system. The only thing you could do is to run a special website that is owned by yourself (as admin for example) that does not have the open_basedir restriction and has full SSH access privileges (not only the chrooted). Do not do this for your users, that would be fatal for your system.
 
Was a solution ever found regarding this? I have tried the script but it does not appear to work. Regarding running the script outside of a subscription on a server. Are you saying it is necessary to run the script on another domain on another server? Or from a domain on an alternative subscription in Plesk?

I am looking for a solution that will check the domain email accounts to see if a particular email address exists, if not, create the email address and send a welcome email.
 
Was a solution ever found regarding this? I have tried the script but it does not appear to work. Regarding running the script outside of a subscription on a server. Are you saying it is necessary to run the script on another domain on another server? Or from a domain on an alternative subscription in Plesk?

I am looking for a solution that will check the domain email accounts to see if a particular email address exists, if not, create the email address and send a welcome email.

Hello,
What is the error you are getting while running the script?
In case you want to run it on the same Plesk server it might be easier to use CLI, the commands for retrieving list of email addresses and creating new email address are available via plesk bin mail. More information can be found in documentation mail: Mail Accounts.
 
Any solution yet? I have the same problem. I want customers to be able to chose their username, select the mailbox name for a list of 35 and generate a password that satisfies Plesk's security requirements.
 
Back
Top