Delete Email One Year Old

How can I clean all the emails that are one year old from all my clients.

Mails are files in /home/user/mail/domain.tld, so basicly you can search all files older than 365 years (find will be your friend) and remove them. But maybe test it first and make a copy of the files :slight_smile:.


Just to add to that, dovecot has some tools that will help you with this, but once again, test, test, test, first.

The first is the ‘doveadm expunge’ command.
Something like this might work. (not tested!)
doveadm -v expunge -u [email protected] before 2019-11-18
If you have it working for one user, then you can run the same query over all of them … at your own risk! You can use doveadm search to get the query right first in fact.

If you want to go on deleting mails over one year old from a mailbox you can add an autoexpunge flag to it. eg, you might autoexpunge a Trash folder to remove mail older than 30 days, and an Inbox over 1 year. Dovecot documentation is your starting point for this.

1 Like