Question
How to delete emails from the command-line or terminal?
Answer
The best way to clear emails in the command line is to use doveadm expunge search commands. You can also clear all emails from a mailbox when using the expunge command without a search query.
Note: Using Dovecot tools to manipulate emails is an administrator task. Consult with your administrator before using Dovecot tools to manipulate email messages in the command line to avoid data corruption or other potential issues. 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.
Warning: Please create a backup of the account before making any changes, as failure to do so can result in irrecoverable data loss.
Procedure to clear emails with a search
- Access the server's command line as the 'root' user via SSH or "Terminal" in WHM.
-
Use the doveadm command 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 "----------";done
Note: Please note that "CPANELEMAIL@DOMAIN.TLD" and "SEARCH-QUERY" must be replaced 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 doveadm command to delete the emails.
# doveadm expunge -u CPANELEMAIL@DOMAIN.TLD mailbox INBOX SEARCH-QUERY
Note: Please note that "CPANELEMAIL@DOMAIN.TLD" and "SEARCH-QUERY" must be replaced with the email address of the account to delete emails from and the search query to locate the emails to be deleted.
Comments
0 comments
Article is closed for comments.