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.

Auto deletion of mails in a mailbox based on age

Discussion in 'E-mail Discussions' started by ebizindia, Dec 28, 2012.

  1. ebizindia

    ebizindia Well-Known Member

    Joined:
    Oct 13, 2005
    Messages:
    72
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Kolkata, India
    cPanel Access Level:
    Root Administrator
    Hi

    I need to auto delete mails older than a certain period (say 30 days) in a mailbox. I am not talking about the mail queue please.

    Why? This is an archival mailbox where we collect auto forwarded mails and while we need to be able to see mails sent and received with a 30 day window, older mails should be deleted to conserve space.

    I am fine if this can be achieved through some settings or even a cron script.

    Please advise.

    TIA
     
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    14,447
    Likes Received:
    195
    Trophy Points:
    63
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Login to Horde Webmail, click Mail on left menu, click Options at top, find Login Tasks section, and set your purge options.

    That area looks like this:

    lgntskscP.jpg
     
  3. ebizindia

    ebizindia Well-Known Member

    Joined:
    Oct 13, 2005
    Messages:
    72
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Kolkata, India
    cPanel Access Level:
    Root Administrator
    1. I cannot see a way to delete inbox mails. The auto archived mails will be in inbox.

    2. I will not be logging to this account (possibly never until I need to review somebody's emails). So the auto deletion has to be independent of that.
     
  4. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    If you set some crons replacing the path with your path to the mailbox folders, the following should delete older than 30 days emails

    New folder:

    /bin/find /home/account/mail/domain.com/user/new ! -mtime -30 -type f -exec rm {} \;

    and if you look at the mail folder periodically, some may be moved to the cur folder even if they're not read:

    /bin/find /home/account/mail/domain.com/user/cur ! -mtime -30 -type f -exec rm {} \;

    Not sure if this cron requires running as root, so if you can't run it under the user, place with the proper cron syntax in:

    /var/spool/cron/root

    such as running one at 2:15 am every night:

    15 2 * * * /bin/find /home/account/mail/domain.com/user/new ! -mtime -30 -type f -exec rm {} \;
     
  5. ebizindia

    ebizindia Well-Known Member

    Joined:
    Oct 13, 2005
    Messages:
    72
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Kolkata, India
    cPanel Access Level:
    Root Administrator
    Thanks kdean. I need something like this. I will test and get back to you.
     
  6. ebizindia

    ebizindia Well-Known Member

    Joined:
    Oct 13, 2005
    Messages:
    72
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Kolkata, India
    cPanel Access Level:
    Root Administrator
    After a bit of testing, I figured out the following to achieve this:

    /bin/find /home/account/mail/domain/user/new -type f -mtime -30 -exec rm {} \;
    /bin/find /home/account/mail/domain/user/cur -type f -mtime -30 -exec rm {} \;

    Do you see any issues with this?

    What was the ! in your command for? Also I think Linux wanted the /type f first and then mtime.
     
  7. kdean

    kdean Well-Known Member

    Joined:
    Oct 19, 2012
    Messages:
    262
    Likes Received:
    12
    Trophy Points:
    18
    Location:
    Orlando, FL
    cPanel Access Level:
    Root Administrator
    The ! is important. ! in programming generally refers to NOT.

    So...

    -mtime -30

    refers to within the last 30 days, while....

    ! -mtime -30

    refers to not within the last 30 days or older than 30 days.

    Not sure why your Linux would want type in a different order but it really shouldn't matter, but UNIX can be an odd one at times.
     
  8. ebizindia

    ebizindia Well-Known Member

    Joined:
    Oct 13, 2005
    Messages:
    72
    Likes Received:
    2
    Trophy Points:
    8
    Location:
    Kolkata, India
    cPanel Access Level:
    Root Administrator
    Thanks kdean. I have updated my command :)
     
  9. webstyler

    webstyler Well-Known Member

    Joined:
    Nov 20, 2003
    Messages:
    432
    Likes Received:
    0
    Trophy Points:
    16
    Hello
    in the last release (11.38) there is any tools for set auto delete of old message in mailboxes ?
    thanks
     
  10. quietFinn

    quietFinn Well-Known Member

    Joined:
    Feb 4, 2006
    Messages:
    998
    Likes Received:
    10
    Trophy Points:
    18
    Location:
    Finland
    cPanel Access Level:
    Root Administrator
  11. konrath

    konrath Well-Known Member

    Joined:
    May 3, 2005
    Messages:
    367
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Brasil
    The best way to remove emails ( 60 days old )



    find /home/a*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/b*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/c*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/d*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/e*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/f*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/g*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/h*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/i*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/j*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/k*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/l*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/m*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/n*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/o*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/p*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/q*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/r*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/s*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/t*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/u*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/v*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/x*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/y*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/w*/mail/*/ -type f -mtime +60 | xargs rm -f
    find /home/z*/mail/*/ -type f -mtime +60 | xargs rm -f
     
Loading...

Share This Page