Windows IIS SMTP Test Scripts
I wrote a couple of Autoit scripts to test if a Windows IIS SMTP server is responding properly.
The first is [download#4]. This guy connects to the local mail relay and sends an email. Simple. You supply it with three command line parameters: from address, to address and subject.
The second, called [download#3], checks the mail queue folder (“c:\Inetpub\mailroot\Queue\”) and if it has any files older than 12 minutes, it restarts the relay service. If you have mail to send and your server looses connectivity to the DNS server, it will generally freak out and start leaving mail in the queue. By restarting the service, the mail will then flush out of the queue.
You will want to schedule the testSMTP script to run, say, once a day. It will send you an email letting you know you are still able to send out the server. This is great for critical monitoring servers. You will want to schedule the mailRoot script to repeat every 30 minutes or so.
Click below to view the code!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ;#########testSMTP######### #include <GUIConstantsEx.au3> if $CmdLine[0] <> 3 Then MsgBox(0, "Missing CLI Parms", "requires 3 command line paraeters." & @CRLF & 'testSmtp.exe [email protected] [email protected] "Subject line"', 3) Exit EndIf ;Opt('MustDeclareVars', 1) ;============================================== ;============================================== ;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!! ;============================================== ;============================================== Example() Func Example() ; Set Some reusable info ;-------------------------- Local $ConnectedSocket, $szData Local $szIPADDRESS = "127.0.0.1" Local $nPORT = 25 ; Start The TCP Services ;============================================== TCPStartup() ; Initialize a variable to represent a connection ;============================================== $ConnectedSocket = -1 ;Attempt to connect to SERVER at its IP and PORT 33891 ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) ; If there is an error... show it If @error Then MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error) ; If there is no error loop an inputbox for data ; to send to the SERVER. Else ;this is sending the mail commands ;TCPSend($ConnectedSocket, "ehlo gregsowell.com" & @crlf) ToolTip("ehlo " & StringMid($CmdLine[1], StringInStr($CmdLine[1], "@") + 1) & "_", 0, 0) TCPSend($ConnectedSocket, "ehlo " & StringMid($CmdLine[1], StringInStr($CmdLine[1], "@")) & @crlf) sleep(1500) ;TCPSend($ConnectedSocket, "mail from:[email protected]" & @crlf) ToolTip("mail from:" & $CmdLine[1] & "_", 0, 0) TCPSend($ConnectedSocket, "mail from:" & $CmdLine[1] & @crlf) sleep(1500) ;TCPSend($ConnectedSocket, "rcpt to:[email protected]" & @crlf) ToolTip("rcpt to:" & $CmdLine[2] & "_", 0, 0) TCPSend($ConnectedSocket, "rcpt to:" & $CmdLine[2] & @crlf) sleep(1500) TCPSend($ConnectedSocket, "data" & @crlf) sleep(1500) ;TCPSend($ConnectedSocket, "Subject:Daily Test" & @crlf & @crlf) ToolTip("Subject:" & $CmdLine[3] & "_", 0, 0) TCPSend($ConnectedSocket, "Subject:" & $CmdLine[3] & @crlf & @crlf) sleep(1500) ;TCPSend($ConnectedSocket, "Daily Test" & @crlf) ToolTip($CmdLine[3] & "_", 0, 0) TCPSend($ConnectedSocket, $CmdLine[3] & @crlf) sleep(1500) TCPSend($ConnectedSocket, "." & @crlf) EndIf EndFunc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ;#####mailRoot####### ; check the mail root folder for windows smtp and if the files are more than 12 minutes old, ; restart the iis service #include <Process.au3> #Include <File.au3> #Include <Array.au3> $fileLocation = "c:\Inetpub\mailroot\Queue\" $FileList=_FileListToArray($fileLocation) If @Error <> 0 Then MsgBox (0,"","No Files\Folders Found.", 2) ;Exit Else ;_ArrayDisplay($FileList,"$FileList") for $x = 1 to $FileList[0] $t = FileGetTime($fileLocation & $FileList[$x], 1) $fileMins = $t[3] * 60 + $t[4] $currentMins = @HOUR * 60 + @MIN ;if $currentMins - $fileMins > 12 or (@HOUR == 1 AND @MIN == 0) Then if $currentMins - $fileMins > 12 Then ToolTip("restarting iis service",0,0) ;restart the service ;World Wide Web Publishing - XP ;World Wide Web Publishing Service - 2k3 ;Simple Mail Transfer Protocol (SMTP) - 2k3 if @OSVersion == "WIN_XP" Then _RunDOS('net stop "World Wide Web Publishing"') Run(@ComSpec & " /c " & 'net stop "World Wide Web Publishing"', "", @SW_HIDE) Else _RunDOS('net stop "World Wide Web Publishing Service"') Run(@ComSpec & " /c " & 'net stop "World Wide Web Publishing Service"', "", @SW_HIDE) _RunDOS('net stop "Simple Mail Transfer Protocol (SMTP)"') Run(@ComSpec & " /c " & 'net stop "Simple Mail Transfer Protocol (SMTP)"', "", @SW_HIDE) EndIf sleep(5000) EndIf Next EndIf if @OSVersion == "WIN_XP" Then _RunDOS('net start "World Wide Web Publishing"') Run(@ComSpec & " /c " & 'net start "World Wide Web Publishing"', "", @SW_HIDE) Else _RunDOS('net start "World Wide Web Publishing Service"') Run(@ComSpec & " /c " & 'net start "World Wide Web Publishing Service"', "", @SW_HIDE) _RunDOS('net start "Simple Mail Transfer Protocol (SMTP)"') Run(@ComSpec & " /c " & 'net start "Simple Mail Transfer Protocol (SMTP)"', "", @SW_HIDE) EndIf |