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.

Deleting All Catch-All Mails Across All Accounts

Discussion in 'E-mail Discussions' started by arsytym, Jan 21, 2015.

  1. arsytym

    arsytym Registered

    Joined:
    Nov 20, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi,
    I need to empty all my catch-all accounts, I have many to do which will take a long time manually

    I already set the catch-all to : Fail to prevent more mail coming in,

    I have probably over 1 million emails in total collectively in these accounts, some have over 200k so
    trying to remove cur folder times out.

    Any ideas what to run with SSH to do this in bulk?

    Thank you
     
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,146
    Likes Received:
    34
    Trophy Points:
    48
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Hello,

    You will have to delete all mail using SSH from cur and new directory which are created under /home/username/mail directory
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,767
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Email sent to the default address is stored in:

    Code:
    /home/$username/mail/cur
    /home/$username/mail/new
    You can delete all of this email through the use of a wildcard and the "rm" command. There is no single command to use, but you could try something such as:

    Code:
    mkdir /root/email-to-delete
    mv /home/*/mail/cur/* /root/email-to-delete/
    mv /home/*/mail/new/* /root/email-to-delete/
    Then, simply delete "/root/email-to-delete" when you have confirmed the emails are no longer required.

    To note, you can ensure emails sent to non-existent email accounts are not delivered to the default address by ensuring your accounts set the "Default Address" to:

    "Discard with error to sender (at SMTP time)"

    Thank you.
     
  4. arsytym

    arsytym Registered

    Joined:
    Nov 20, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,

    Thank you for replying to my question.

    I ran the command,

    mv /home/*/mail/cur/* /root/email-to-delete/


    But I received This:

    -bash: /bin/mv: Argument list too long


    I have set all existing account to :fail now - just need to clear out these folders :)
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,767
    Likes Received:
    662
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    You may find this third-party application helpful if you lack command-line experience:

    Config Server Mail Manage

    Otherwise, searching for "/bin/mv: Argument list too long" on a search engine will yield useful results.

    Thank you.
     
  6. ethical

    ethical Well-Known Member

    Joined:
    Apr 7, 2009
    Messages:
    79
    Likes Received:
    2
    Trophy Points:
    8
    just wanted to save others the time in "searching for the answer" as Michael suggested

    use
    Code:
    find /home/*/mail/cur/* -type f | xargs -i mv "{}" /root/email-to-delete/
    
    or this and slowly increase the mtime value until you can finish with the above line
    
    find /home/*/mail/cur/* -type f -mtime +1 -print | xargs -i{} mv {} /root/email-to-delete/
    
    
    in my cause my list was even too long for the find command, even when i set it to just do files modified in the lastday (-mtime +1) so i did this and stepped through the alphabet for the home dirs util I could run the above command without error

    Code:
    find /home/a*/mail/new/* -type f -print | xargs -i{} mv {} /root/email-to-delete/
    
     
    #6 ethical, May 2, 2016
    Last edited: May 2, 2016
Loading...

Share This Page