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!

SOLVED How can I safely delete emails from forwarded accounts?

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

  1. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,178
    Likes Received:
    6
    Trophy Points:
    168
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,792
    Likes Received:
    83
    Trophy Points:
    78
    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..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,178
    Likes Received:
    6
    Trophy Points:
    168
    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!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,714
    Likes Received:
    1,794
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Kent Brockman

    Kent Brockman Well-Known Member

    Joined:
    Jan 20, 2008
    Messages:
    1,178
    Likes Received:
    6
    Trophy Points:
    168
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice