Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED How can I safely delete emails from forwarded accounts?

Discussion in 'E-mail Discussions' started by Kent Brockman, Jun 5, 2017.

  1. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,160
    Likes Received:
    5
    Trophy Points:
    68
    Location:
    Buenos Aires, Argentina
    cPanel Access Level:
    Root Administrator
    Twitter:
    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
     
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,484
    Likes Received:
    60
    Trophy Points:
    28
    Location:
    India
    cPanel Access Level:
    Root Administrator
    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..
     
  3. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,160
    Likes Received:
    5
    Trophy Points:
    68
    Location:
    Buenos Aires, Argentina
    cPanel Access Level:
    Root Administrator
    Twitter:
    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!
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

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

    Thank you.
     
  5. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,160
    Likes Received:
    5
    Trophy Points:
    68
    Location:
    Buenos Aires, Argentina
    cPanel Access Level:
    Root Administrator
    Twitter:
    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
     
Loading...

Share This Page