If you use Postfix and Dovecot you will at some point be filled with lots of SPAM emails and you’ll want to empty or clear your mailboxes. I had a mailbox setup for my website, and it piled up to over 200MB worth of junk mail that was wasting space on my server. I googled how to clear the mailboxes, but couldn’t find a clear answer. So that’s the purpose of this little guide. Just to show you exactly how to empty all the SPAM mail from your dovecot mailboxes. You can specify which mailboxes you’d like to empty, but for this example, I’ll show you how to clear all mailboxes.
Step 1. Login to SSH Terminal
You’ll need to login via SSH and with ROOT login details.
Step 2. Execute command
doveadm expunge -A mailbox INBOX ALL
This tells the server to purge/clear/empty “-A” which means all, mailboxes in the folder INBOX. If you wish to only do a certain email address, run this command
doveadm expunge -u firstname.lastname@example.org mailbox INBOX ALL
Replace the example email address with the real one.
Step 3. Done!
You’re done! All mailboxes are cleared and emptied. Now you can have a cleaner server 🙂
Note: This clears/empties ALL Mail from the INBOXES. Even the GOOD mail you may want to keep.