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 Mails with Cron ???

Discussion in 'cPanel Developers' started by mesut85u2, Mar 21, 2015.

  1. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    Hi,

    I want to delete all mails once a day but i couldn't do it. I used this command:


    rm /home/{username}/mail/domain.net/test/cur/*']{domain.com}/{mailusername}/cur/*

    I deleted only inbox mails. But i want to delete inbox and sent mails.

    help me !!!
     
    #1 mesut85u2, Mar 21, 2015
    Last edited by a moderator: Apr 14, 2015
  2. 24x7ss

    24x7ss Well-Known Member

    Joined:
    Sep 30, 2014
    Messages:
    271
    Likes Received:
    16
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    Ofcourse you can do this using cron. You can put below two commands in one file and set cron for that file.
    Suppose create /root/maildelete.txt. Put below commands in that file :

    rm -rf /home/{username}/mail/{domain.com}/{mailusername}/cur/*
    rm -rf /home/{username}/mail/{domain.com}/{mailusername}/sent/*

    and then set cron for /root/maildelete.txt
     
  3. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    thanks for your help

    the command works for inbox, but not work for sent folder. there is not a "sent" folder. and i don't know where sent mails are storing... I add the my mail screenshot...

    If you know, how can i empty sent folder?

    One more, what is the meaning of "-rf" command?
     

    Attached Files:

  4. 24x7ss

    24x7ss Well-Known Member

    Joined:
    Sep 30, 2014
    Messages:
    271
    Likes Received:
    16
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    I forgot to mention the .(dot) for Sent folder. Use below syntax:

    rm -rf /home/{username}/mail/{domain.com}/{mailusername}/.sent/*

    Further, r means recursive and f means forcefully.
     
    danrussell likes this.
  5. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    thanks a lot for your help.

    and one more thing i found

    rm -rf /home/{username}/mail/{domain.com}/{mailusername}/.Sent/cur/*

    the bold part is important.
     
  6. 24x7ss

    24x7ss Well-Known Member

    Joined:
    Sep 30, 2014
    Messages:
    271
    Likes Received:
    16
    Trophy Points:
    18
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Twitter:
    Ok, Thanks for the update.

    We are glad that your issue gets fixed :)
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  8. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    Hi, I need one more help...

    All personels are using mail system, and all mails are forwarding personals' other mail address: for example, all mails are forwarding from main.address@domain.com to personel@gmail.com and it is working best.
    Problem: If you don't open webmail interface, cron job doesn't delete inbox mails. If you access webmail interface (you don't need to read mails), cron job delete inbox mails. WHY???

    How can i delete inbox mails without access webmail interface because of forwarding all mails???
     
  9. danrussell

    danrussell Well-Known Member

    Joined:
    Nov 5, 2014
    Messages:
    60
    Likes Received:
    3
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hi :),

    The cronjob should delete the emails in "cur" directory without accessing the webmail. Please check if you have set the cron correctly.
     
  10. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    hi danrussell,

    my cron job code is:
    rm -rf /home/username/mail/domain.net/mail_user_name/cur/*

    is there any mistake?
     
  11. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    I think i found the right code:

    find /home/{username}/mail/{domain.com}/{mail-user-name}/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \;

    example:
    username : sitenm
    domain: sitenm.com
    mail-user-name : info (info@sitenm.com)

    find /home/sitenm/mail/sitenm.com/info/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \;
     
  12. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner

    I am testing this code, i hope it works well... I will write the stuation...
     
  13. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  14. mesut85u2

    mesut85u2 Member

    Joined:
    Mar 21, 2015
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Turkey
    cPanel Access Level:
    Website Owner
    It is working best, no problem... I am using that. thanks your helps.
     
  15. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    675
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator

Share This Page