Question
How to delete all or some emails from a mailbox without logging in to the mailbox?
Answer
Right now this feature is not implemented in Plesk. Please vote for it on our Plesk UserVoice portal: the most popular features are likely to be included in one of the next Plesk versions.
As a workaround, one of the following methods can be applied:
-
Delete the mailbox from the server and create it again - all emails will be removed;
-
Directly manipulate with Dovecot administrative utilities on a server:
Note: SSH access to the server is required.
Mailbox should be enabled: The "Mailbox" option is checked in Domains > example.com > Email Addresses > [email protected]-
Get the information about existing mailboxes:
# doveadm mailbox list -u [email protected]
INBOX
INBOX.Spam
INBOX.Drafts
INBOX.Trash
INBOX.Sent -
Remove all messages older than a week from the
'Inbox'
folder for the particular mailbox[email protected]
:# doveadm expunge -u [email protected] mailbox '*' before 1w
-
Remove all messages older than a week from all folders except
'Inbox'
folder for the particular mailbox[email protected]
:# doveadm expunge -u [email protected] mailbox INBOX.'*' before 1w
-
Remove all messages from
'Drafts'
folder on allexample.com
domain mailboxes:# for i in $(plesk bin mail -l | tr 't' ' ' | cut -d' ' -f 3- | grep example.com); do doveadm expunge -u "$i" mailbox INBOX.Drafts all; done
-
Delete all messages from the particular mailbox
[email protected]
:# doveadm expunge -u [email protected] mailbox 'INBOX' all
# doveadm expunge -u [email protected] mailbox 'INBOX.*' all -
Remove all messages from
'Spam'
and'Trash'
folders from all mailboxes on all domains:# for i in $(plesk bin mail -l | tr 't' ' ' | cut -d' ' -f 3-); do doveadm expunge -u "$i" mailbox INBOX.Spam all; done
# for i in $(plesk bin mail -l | tr 't' ' ' | cut -d' ' -f 3-); do doveadm expunge -u "$i" mailbox INBOX.Trash all; doneNote: courier-imap does not support these commands
-
Also the procedure can be optimized by deleting all emails for all mailboxes specified in a file:
-
Download the following script and grant permissions:
# wget https://github.com/plesk/kb-scripts/raw/master/mailbox-doveadm-expunge/mailbox-doveadm-expunge.sh && chmod +x ./mailbox-doveadm-expunge.sh
-
Edit/Create file mbox.txt and specify all mailboxes for you wish to remove emails from:
-
Execute the script:
# ./mailbox-doveadm-expunge.sh
-
-
More information on these features could be found in official Dovecot documentation articles: