Introduction
The UAPI can be used to delete email older than a specified age. This article provides the steps to do this.
Messages deleted with the UAPI are removed permanently and NOT placed in the .Trash
folder.
Procedure
- Access the server's command line.
- Run the following command to find the guid of the mailbox from which to remove the mail.
uapi --user=$username Mailboxes get_mailbox_status_list account='$user@domain.tld'|grep -A1 guid
Please note that "$username" must be replaced with the username of the cPanel account the email address is on, and "$user@domain.tld" must be replaced with the email address. - Run the following command to delete the emails.
uapi --user=$username Mailboxes Mailboxes expunge_messages_for_mailbox_guid account='$user@domain.tld' mailbox_guid='$guid' query='sentbefore $Xd'
Please note that "$username" must be replaced with the username of the cPanel account the email address is on, "$user@domain.tld" must be replaced with the email address, "$guid" must be replaced with the mailbox guid found in the previous command, and "$X" must be replaced with the maximum age in days of an email to be kept.