Hi All,
Today I am going to give you a script . When the folders of SMTP service like pickup, badmail, Drop and queue becomes full or reaches to some number the below script will kill the SMTP process and will again start the process. and a output log file will be created when the process is killed.
Modify the below script as per you environment.
@echo off
set /a c=1
for /f %%i in ('dir C:\inetpub\mailroot\Pickup ^| findstr /i /c:"file(s)"') do set count=%%i
if %count% gtr 10 (
for /f "tokens=2 delims= " %%P IN ('tasklist /FO Table /M "SMTPSVC*" /NH ') DO (TASKKILL /F /PID %%P)
net start smtpsvc
echo %date% %time% %count% - Pickup Folder has reached the limit >>"C:\smtp.log"
)
endlocal
for /f %%i in ('dir C:\Inetpub\mailroot\Queue ^| findstr /i /c:"file(s)"') do set count=%%i
echo count=%count%
if %count% gtr 10 (
for /f "tokens=2 delims= " %%P IN ('tasklist /FO Table /M "SMTPSVC*" /NH ') DO (TASKKILL /F /PID %%P)
net start smtpsvc
echo %date% %time% %count% - Queue folder has reached the limit >>"C:\smtp.log"
)
endlocal
for /f %%i in ('dir C:\Inetpub\mailroot\Drop ^| findstr /i /c:"file(s)"') do set count=%%i
echo count=%count%
if %count% gtr 10 (
for /f "tokens=2 delims= " %%P IN ('tasklist /FO Table /M "SMTPSVC*" /NH ') DO (TASKKILL /F /PID %%P)
net start smtpsvc
echo %date% %time% %count% - Drop folder has reached the limit >>"C:\smtp.log"
)
endlocal
for /f %%i in ('dir C:\Inetpub\mailroot\Badmail ^| findstr /i /c:"file(s)"') do set count=%%i
echo count=%count%
if %count% gtr 10 (
for /f "tokens=2 delims= " %%P IN ('tasklist /FO Table /M "SMTPSVC*" /NH ') DO (TASKKILL /F /PID %%P)
net start smtpsvc
echo %date% %time% %count% - Badmail folder has reached the limit >>"C:\smtp.log"
)
endlocal
Note:
In the below line change the value of 10 to any number you want.
""if %count% gtr 10 ""
when the files reaches to 10 the SMTP process will be killed and a output will be written in a file names SMTP.log
Comments