Can I use cron to delete old spam and trashed mail?

I have several users that don’t seem willing/able to clear out their Spam and Trash folders. Most access their email via POP and so their inboxes are being cleared, but their Spam folders now have several months’ worth of spam.

I would like to run these this bash script once per day, using crontab.

cd /home/user-data/mail/mailboxes
find -wholename "./*/*/.Spam/*/**" -mtime +60 -exec rm {} \;
find -wholename "./*/*/.Trash/*/**" -mtime +60 -exec rm {} \;

The goal is to delete any emails in Spam and Trash folders that are older than 60 days. Are there any better ways of doing this? Are there any dangers to doing this?

Thanks in advance.


did you implement this?

I did. It seems to work. Just make sure to replace “” with your actual box domain name.

1 Like

One more questions, what is the bash script to delete all emails (inbox, sent, draft, trash, spam, etc.), older than 90days?

Is this the correct one?

cd /home/user-data/mail/mailboxes
find -wholename "./*/*/*/*/**" -mtime +90 -exec rm {} \;