SOLVED **SOLVED** Fix missing mail directories

webdesires

Registered
Sep 21, 2020
4
0
1
cannock
cPanel Access Level
Root Administrator
Hello guys,

I have an issue... I ran a couple of commands on our server to clear all cpanel default mail account emails... however the command also deleted the folders! so all /home/*/mail/cur/ and /home/*/mail/new/ folders are missing from ALL accounts.

This is causing lots of bounce email issues when crons etc are mailing these accounts.

I have run the mailperm fix script but it did not create any of the directories - what can i do to recreate all these missing directories as I obviously cannot go do this manually... lol
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
12,481
1,966
363
cPanel Access Level
Root Administrator
Hey there! These directories aren't special in any way, and only hold content and not any passwords, so they should be easy enough to recreate. I don't have a custom script handy, but a for-loop script that goes through all the usernames on the server and recreates them would likely be the easiest method.

I can tell you both cur and new have user:user ownership with 751 permissions.
 

webdesires

Registered
Sep 21, 2020
4
0
1
cannock
cPanel Access Level
Root Administrator
yeah this is what I need, some script to do this... I'm not proficient in bash or anything so cannot do it. So looking for something that will fix this issue since there is over 100 cpanel accounts :(
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
12,481
1,966
363
cPanel Access Level
Root Administrator
I'm always hesitant to post any type of custom script on the Forums because once it's out there it's available forever, and I don't want to be responsible for any damage to a server. I also don't have anything ready-made for this situation so I'd also have to do some design work. It might be best to work directly with a server administrator if you're not able to come up with a good script.
 

webdesires

Registered
Sep 21, 2020
4
0
1
cannock
cPanel Access Level
Root Administrator
I have gone ahead and figured out how to do everything I needed to, below is everything I did and how I fixed it, for anyone else in the same dire situation as I was in.

So firstly I was removing all mail for default cPanel accounts on the server, because we had many accounts just building up huge amounts of useless mail.
WARNING! This code will delete the /cur/ and /new/ directories, which the code below will fix.:

find /home/*/mail/cur/ -exec rm -rf {} +
find /home/*/mail/new/ -exec rm -rf {} +


So this destroyed the folders causing all those accounts to now bounce mail...
To fix this there are 2 commands below which recreate these folders in all cPanel accounts:

for dir in /home/*/; do mkdir -- "$dir/mail/cur"; done
for dir in /home/*/; do mkdir -- "$dir/mail/new"; done


The final problem is that now all these folders are root, and the mailperm script cannot fix these folders.
To fix this the below 2 commands will chown all the folders to each respective cPanel user:

for i in `ls /var/cpanel/users`; do chown $i:$i /home/$i/mail/cur/; done
for i in `ls /var/cpanel/users`; do chown $i:$i /home/$i/mail/new/; done


Finally now there is just folder rights issues, which you can use cPanels mailperm script to fix everything up:

/scripts/mailperm

Thanks!