mesut85u2

Member
Mar 21, 2015
9
1
1
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 !!!
 
Last edited by a moderator:

24x7ss

Well-Known Member
Sep 30, 2014
272
17
68
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
 

mesut85u2

Member
Mar 21, 2015
9
1
1
Turkey
cPanel Access Level
Website Owner
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
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?
 

Attachments

24x7ss

Well-Known Member
Sep 30, 2014
272
17
68
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.
 
  • Like
Reactions: danrussell

mesut85u2

Member
Mar 21, 2015
9
1
1
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.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
Hello,

I am happy to see the solution provided was helpful. Thank you for updating us with the outcome.
 

mesut85u2

Member
Mar 21, 2015
9
1
1
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 [email protected] to [email protected] 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???
 

danrussell

Well-Known Member
Nov 5, 2014
61
4
58
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.
 

mesut85u2

Member
Mar 21, 2015
9
1
1
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 ([email protected])

find /home/sitenm/mail/sitenm.com/info/ -type d \( -name cur -o -name new \) -exec find {} -type f -delete \;
 
  • Like
Reactions: alexio454

mesut85u2

Member
Mar 21, 2015
9
1
1
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 ([email protected])

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

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

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
Feel free to update us with the outcome after testing out your cron job.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
I am happy to see the issue is now resolved. Thank you for updating us with the outcome.