The following provides guidance on how to get started with removing email messages via the command line with Dovecot tools.
Please note that an administrator should always use Dovecot tools to manipulate email messages on the command line to avoid data corruption or other potential issues.
Please keep in mind that the process of manipulating email messages via the command line is an administrative task that is not related to cPanel or the basic configuration of cPanel. cPanel is not able to provide support for the steps provided in the guide below.
Please note that a backup of the account should be taken before any changes are made, as failure to create a backup beforehand can result in irrecoverable data loss.
- Access the server's command line as the 'root' user via SSH or "Terminal" in WHM.
- Use the
doveadmcommand to locate the emails to delete.
doveadm search -u CPANELEMAIL@DOMAIN.TLD mailbox INBOX SEARCH-QUERY | while read guid uid;do doveadm fetch -u CPANELEMAIL@DOMAIN.TLD "hdr.subject date.saved" mailbox-guid $guid uid $uid;echo "----------";donePlease note that "CPANELEMAIL@DOMAIN.TLD" and "SEARCH-QUERY" with the email address of the account to delete emails from and the search query to locate the emails to be deleted.
- Verify that the previous command returns the correct messages.
- Use the
doveadmcommand to delete the emails.
doveadm expunge -u CPANELEMAIL@DOMAIN.TLD mailbox INBOX SEARCH-QUERYPlease note that "CPANELEMAIL@DOMAIN.TLD" and "SEARCH-QUERY" with the email address of the account to delete emails from and the search query to locate the emails to be deleted.