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

  PowerShell DSC log amount issue on operating system drive Overview Problem Impact Microsoft Ticket (Workaround) solution References Overview When using PowerShell DSC on a configured system in some (seldom) cases it can lead to log amount issues in a specific folder. The following folder grows (over time) so several GB size holding hundreds and thousands of JSON log files as visible in the following screenshot: Also sometimes it looks like this: Problem The problem is (but must not be) related to DSC configuration issues as far as it could be analyzed. The log folder „Configuration Status“ is filled with sometimes up to 7 Megabyte sized JSON files. This log folder (based on our analysis) is used for sending reports to report server but is not cleaned up automatically. Impact Some PowerShell DSC managed systems need extensive disk space due to log directory grown to 40 Gigabyte plus. This causes an alert in disk space / availability monitoring and could in some cases lead to non w...

System Volume Information is taking more space

On one of the servers (running Windows Server 2012 R2) I faced a problem with the lack of free space on a system drive. I have cleared all resource-consuming locations ( WinSxS , TEMP directories, user profiles,  outdated updates , etc.), but it didn’t have any evident effect. At last, I have found that a large part of a system disk has been occupied by  System Volume Information  folder. Let’s consider why we need System Volume Information folder in Windows systems, what is stored in it and how to clean up it. Note . The instructions given in this article are applicable to other Windows versions as well:   Windows 10, Windows 7, Windows 8, Windows 2008 R2, Windows 2012 / 2012 R2. System Volume Information  folder is in the root of each disk. System data related to system recovery and Shadow Copy Service are stored in it. By default it is hidden and only the SYSTEM has access to it. Even the administrator cannot open it and look through the contents of th...

Fix Windows Activation failed due to Software Protection Service error code 0xc0000022

  With Windows Activation, the fun never ends! Recently when I was working on a windows 2016 server activation. Instead of activation of windows.  Instead, I got error code  0xc0000022 , and the perfectly valid built-in OEM key would not re-activate the same Windows on the same hardware – no matter what I did. It turns out the culprit was an ‘ access denied ‘ error in the  Software Protection  service… The error  0xc0000022  means that the  Software Protection Service  (SPS) wouldn’t start. If you’re having a similar activation error – especially with resetting an OEM version of Win 2016 on your server – then the first thing to do is verify that the SPS is the culprit. Check the SPS First, click  Start  (the windows logo button on the taskbar). Type:  services Click the  Services  app icon. Next, scroll down and find  Software Protection , and double-click it to view the settings: Make sure that  Startup typ...