Hi,
I have a vbscript that polls the presence of files in a spool folder, and sends out an email when the poll value exceeds a threshold (in my case 5 minutes). The script works like a charm most of the times, but at other times, it fails to send the email alert. I have used CDO for sending the email alerts, and the SMTP server name and other relevant fields related to email delivery are fine. The logfile entries are fine, and the poll values are correctly updated in the excel file; like I mentioned before, 40% of the times, the script delivers the email alert without any issues.
Has anyone else faced a similar situation? Any tips would be welcome.
Here is my code:
on error resume next
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
strcomputer = "myserver"
objExcel.Cells(1,1) = "FILENAME"
objExcel.Cells(1,2) = "FIRST POLLED TIME"
objExcel.Cells(1,3) = "POLL VALUE"
strPath = "mypath"
set logfile = oFSO.CreateTextFile("logfile.txt")
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "alert on Printer Out queue in " &strcomputer
objMessage.From = "my email address"
objMessage.To = "recipient list separated by semi-colons"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "my smtp server name"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
blankfile = 0
do while Hour(Now())>=7 or hour(now())<=6
Set oFolder = oFSO.GetFolder(strPath)
counter = oFolder.Files.count
if counter >10 then
logfile.writeline "There are "&counter&" files in the location "&strPath&", "&date&", "&time
objMessage.TextBody = "There are more than 10 files in the Printer Out-queue on "&strcomputer&". This script will be paused.Please check the queue"
objMessage.send
else
For Each oFile In oFolder.Files
name = oFile.name
if name = "" then
blankfile = blankfile+1
else
logfile.writeline name &", "&date&", "& time
flag = 1
usedRowsCount = objWorkSheet.UsedRange.Rows.Count
For i = 1 to UsedRowsCount
test = objExcel.cells(i,1).value
if name = test then
flag = 0
call duplicatevalue(i,name)
end if
next
if flag = 1 then
call updatenewcell(i, name)
end if
end if
next
end if
wscript.sleep(300000)
loop
sub updatenewcell(i,name)
objExcel.Cells(i,3).value = 0
objExcel.Cells(i,2).value = time
objExcel.Cells(i,1).value = name
end sub
sub duplicatevalue(i,name)
objExcel.Cells(i,3).value = objExcel.Cells(i,3).value + 1
if objExcel.Cells(i,3).value >0 then
alertval = objExcel.Cells(i,3).value
newalertval = alertval*300
newalertval = newalertval/60
objMessage.TextBody = "Check Printer OutQueue; file stuck in corresponding folder for "&newalertval&" minutes on server: "& strComputer
objMessage.Send
end if
end sub