Skip to main content

Script to kill the SMTP service when the folders in mailroot reaches to a certain number


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

Popular posts from this blog

ESM Log size is full - How to clear

                                            ESM log Size is full ---- How to Clear If your getting the below error in event viewer you can follow the below steps and solve it. Generally when we open Dell open manage console, suddenly we see that Hardware log status is showing critical and event logs are filling saying ESM log is full... We need to clear the ESM logs regularly before it reaches 100%. However please follow the below command and procedure before clearing the logs. Open Dell Manage console, go to logs tab. Then select ESM logs, you will see an export option. Export the logs and save it on local drive for future use. Now open command prompt and Runas administrator. Type omconfig system esmlog action=clear Done, ...

The system cannot log you on due to the following error: The RPC server is unavailable

IF your login to windows 2003 and your getting the below error then do the below steps and you can login to the PC. login to any server in the same subnet. open CMD in elevated permission open registry editor go to File---------->connect to network registry type the effected server name and open it go to the below location and create a new DWORD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server Create a new key selecting Dword and name it as IgnoreRegUserConfigErrors now double click it and give a value as 1. after that do the RDP and it will work.
  Remove "Open in new window" option from Windows Explorer right-click menu Hi Guys today we will see how to block the "Open in New Windows" tab in the file explorer menu. Please see the below screenshot which is showed below. Create the appropriate REG file(s) using this code and then run them: ADD 'Open in a New Window' Option Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Folder\shell\opennewwindow] "MUIVerb"="@shell32.dll,-8517" "MultiSelectModel"="Document" "OnlyInBrowserWindow"="" "LaunchExplorerFlags"=dword:00000001 [HKEY_CLASSES_ROOT\Folder\shell\opennewwindow\command] "DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" REMOVE 'Open in a New Window' Option Windows Registry Editor Version 5.00 [-HKEY_CLASSES_ROOT\Folder\shell\opennewwindow] "MUIVerb"="@shell32.dll,-8517" "MultiSelectModel"="Document...