SOLVED How can I safely delete emails from forwarded accounts?

Kent Brockman

Well-Known Member
PartnerNOC
Jan 20, 2008
1,272
63
178
Buenos Aires, Argentina
cPanel Access Level
Root Administrator
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
 

24x7server

Well-Known Member
Apr 17, 2013
1,911
96
78
India
cPanel Access Level
Root Administrator
Twitter
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..
 

Kent Brockman

Well-Known Member
PartnerNOC
Jan 20, 2008
1,272
63
178
Buenos Aires, Argentina
cPanel Access Level
Root Administrator
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!
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello,

I'm glad to see it's working as intended. I'm marking this thread as solved.

Thank you.
 

Kent Brockman

Well-Known Member
PartnerNOC
Jan 20, 2008
1,272
63
178
Buenos Aires, Argentina
cPanel Access Level
Root Administrator
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