Hi Guys,
Today I am going to give you a script which can be set in the scheduled tasks and made to run every 1 Hrs or as per your wish. Once this script runs it will check the 4 folders in Mailroot and see if its reached the limit (10) which you have set in the script and restarts the SMTP service.
This will prevent the SMTP service hung and many problems which are associated with SMTP server.
The script is given below Copy it in notepad and save it as .bat extension so that it becomes a batch script.
@echo off
setlocal
set /a count=0
for /f %%i in ('dir E:\Inetpub\mailroot\Badmail ^| findstr /i /c:"file(s)"') do set count=%%i
echo count=%count%
if %count% GTR 10 (
net stop smtpsvc & net start smtpsvc
)
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 (
net stop smtpsvc & net start smtpsvc
)
endlocal
for /f %%i in ('dir E:\Inetpub\mailroot\Pickup ^| findstr /i /c:"file(s)"') do set count=%%i
if %count% GTR 10 (
net stop smtpsvc & net start smtpsvc
)
endlocal
for /f %%i in ('dir F:\Inetpub\mailroot\Queue ^| findstr /i /c:"file(s)"') do set count=%%i
echo count=%count%
if %count% GTR 10 (
net stop smtpsvc & net start smtpsvc
)
endlocal
Note: Change the 10 is the number of files which needs to be when you want the SMTP service to be restarted.
Comments