Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Feb 2004
    Location
    Montreal
    Posts
    63

    Arrow how to auto delete all emails older than 2 years (cpanel)? Any scripts?

    Hello,

    I remember there used to be an Email Aging option in cPanel that is no longer available. I'm looking for something similar that I can apply to all accounts.

    Basically, I would like to be able to delete all emails on the server that are older than 2 years.

    Any scripts or way of doing this ?

    Thank you.

  2. #2
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Lightbulb

    Quote Originally Posted by ramystyle View Post
    Basically, I would like to be able to delete all emails on the server that are older than 2 years.

    Any scripts or way of doing this ?
    You can simply run a find against all the standard mail folders
    for mail that is older than two years:
    Code:
     find -P /home/*/mail/*/*/cur -mtime '+729'
     find -P /home/*/mail/*/*/new -mtime '+729'
    The above will give you a list of all the mail files older than two years
    and you can either pipe that into 'xargs' for a very quick and dirty way
    of doing that pipe into a file and then have a script parse the file to
    do whatever you would like. Here is a very basic example:

    Code:
    #!/bin/bash
    IFS="$"
    
    cd /home
    
    find -P /home/*/mail/*/*/* -mindepth 1 -maxdepth 1 -mtime '+729' | while read OLDMAIL; do
      echo "Now deleting ${OLDMAIL} ..."
      rm -f "${OLDMAIL}"
    done
    (Incidentally the 729 is the number of days old the file must be greater)

    You could delete the "echo" line and add this basic code to a cronjob
    and have your server auto delete all mail older than 2 years or
    whatever length of time that you want.
    Last edited by Spiral; 06-14-2009 at 12:46 PM.

Similar Threads & Tags
Similar threads

  1. Email aging - Delete emails older than.. on server
    By ramystyle in forum E-mail Discussions
    Replies: 1
    Last Post: 01-21-2011, 12:39 PM
  2. How to delete all mails on server older than X years..
    By ramystyle in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-07-2008, 03:29 AM
  3. how to auto reject and delete emails like this?
    By roby2k in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 02-07-2007, 08:59 AM
  4. Spamassassin Auto Delete Spam Emails
    By cheemin in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 09-01-2006, 12:15 AM
  5. Delete emails from spam box older than x days
    By Netmaking in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 12-02-2004, 09:05 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube