• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    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.

Question Is possible delete all mailboxes at once using REST API v2?

Obistar

New Pleskian
Hi, dear plesk community,
please tell me how can i delete all mailboxes at once using REST API v2?


This is the correct way to delete one mailbox but I need to delete all created mailboxes one time.

# curl -k -X POST -u admin:password "[URL]https://203.0.113.2:8443/api/v2/cli/mail/call[/URL]" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"params\": [ \"--remove\", \"[EMAIL][email protected][/EMAIL]\" ]}"
 
If you go to https://your_plesk_url/api/v2/ you will see that there are no email objects for REST API operations. Only domains, clients, extensions, databases, etc. So, you can use the CLI call for mail command as you wrote in your post. But this command can be executed only for one mailbox. So, there is no ability for mass mailbox deletion with REST API calls.

But you can use the following script for removing all mailboxes:

Code:
# for i in `mysql -uadmin -p\`cat /etc/psa/.psa.shadow\` psa -Ns -e "select concat(mail.mail_name,\"@\",domains.name) as address from mail,domains,accounts where mail.dom_id=domains.id and mail.account_id=accounts.id order by address"`; do /usr/local/psa/bin/mail -r $i; done
 
Back
Top