How can I safely delete emails from forwarded accounts?
Hello guys. Today I have this scenario: two large customers have hundred of email accounts which are being forwarded to those users' personal Gmail/Yahoo/Hotmail accounts. The physical email account at cPanel is needed because they have to reply using the account's SMTP. Due to this, their webmails are rapidly filling their quota with emails, so that the IT guy (me) has to empty those emails accounts manually :(
My question is: what bash command should I run to have this task automated via cronjob?
I bet this can be cleanly performed by running a weekly cronjob emptying all those accounts.
The idea would be to delete this:
rm -rf /home/username/mail/domainname.com/user1/cur/*
rm -rf /home/username/mail/domainname.com/user2/cur/*
rm -rf /home/username/mail/domainname.com/user3/cur/*
....
rm -rf /home/username/mail/domainname.com/user56/cur/*
So, can I simply put those commands in a .sh file to be called via cronjob weekly? or should I take anything else in account to avoid anything that could crash those accounts?
I come doing this manually since a couple weeks and nothing has been broken.
Best regards
-
Hi, The command " rm -rf /home/username/mail/domainname.com/user*/cur/* " does looks to be fine to remove the mail on rotational basis.. If you are too worried about this, you can just initiate account backup in the beginning of the script, so it will take a backup and then remove it.. 0 -
Great. I've tested it and works great. The key is to empty both folders: rm -rf /home/username/mail/thedomain.com/emailaccount/cur/* rm -rf /home/username/mail/thedomain.com/emailaccount/new/* Thanks! 0 -
Hello, I'm glad to see it's working as intended. I'm marking this thread as solved. Thank you. 0 -
Addendum: Yet the previous steps works. It's needed a final step to execute after every clean task: /scripts/generate_maildirsize --verbose --allaccounts --force --confirm username This will reset the cPanel stats of usage of every account, so that disk usage is correctly displayed. Best regards 0
Please sign in to leave a comment.
Comments
4 comments