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

    https://survey.webpros.com/

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