G'day,
I have written this short vbs script to send an e-mail when there are errors the previous day, with details of those errors.
Save the script to any directory, and then create a scheduled task to run it once per day. I run mine (arbitrarily) at 7.00 am.
I haven't tested the first of each new month part of the script as yet, but I will update as appropriate if needed.
There are some 'change this to suit' throughout the script, make sure that you change them.
Save the script with a .vbs extension, something like eMailErrors.vbs
All care taken, no responsibility (but in saying that, this doesn't actually change anything on your system, just sends an e-mail)
Code:
Option Explicit
const g_sBNFrom = "Mail Server" ' change this to suit
const g_sBNFromAddress = "server@domain.com" ' change this to suit
const g_sAdminPassword = "secret" ' change this to suit
dim MessageRecipientName, MessageRecipientAddress, MessageSubject
dim oApp, s, oMessage
Dim FSO, FileIn, Filebase, OBJfile
dim syear, smonth, sday, imonth, iday, iyear
Filebase = "C:\Program Files\hMailServer\Logs\ERROR_hmailserver_"
MessageRecipientName = "Matt" 'change this to suit
MessageRecipientAddress = "matt@domain.com" 'change this to suit
MessageSubject = "Hmailserver Errors" 'change this to suit
Set FSO = CreateObject("Scripting.FileSystemObject")
sYear = year(now)
iMonth = Month(now)
iDay = day(now)-1
If iDay = 0 Then 'If today is the first day of the month
iMonth = iMonth - 1
End If
If iMonth = 4 OR iMonth = 6 OR iMonth = 9 Or iMonth = 11 Then
iDay = 30
End If 'Set last day of last month
If iMonth = 1 OR iMonth = 3 OR iMonth = 5 OR iMonth = 7 OR iMonth = 8 OR iMonth = 10 Then
iDay = 31
End If 'Set last day of last month
If iMonth = 2 Then
If iYear/4 = int(iYear/4) and iYear/100 <> int(iYear/100) Then
iDay = 29
Else
iDay = 28
End If
End If 'Set last day of last month if last month is Feb and checks for Leap Year
If iMonth = 0 Then
iYear = iYear - 1
iMonth = 12
iDay = 31
End If 'Set last Month and Day is today is Jan 1
If iDay < 10 Then
sDay = "0" + cstr(iDay)
Else
sDay = cstr(iDay)
End If 'Make all days two digits
If iMonth < 10 Then
sMonth = "0" + cstr(iMonth)
Else
sMonth = cstr(iMonth)
End If 'Make all Months two digits
sYear = cstr(iYear) 'Set Year
filein = filebase + sYear + "-" + sMonth + "-" + sDay + ".log"
If fso.FileExists(Filein) Then
set OBJfile = FSO.opentextfile(filein,1,0)
While Not OBJfile.atendofstream
s = s & OBJfile.readline
Wend
OBJfile.close
set Objfile = nothing
Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", g_sAdminPassword)
Set oMessage = CreateObject("hMailServer.Message")
oMessage.From = g_sBNFrom & " <" & g_sBNFromAddress & ">"
oMessage.FromAddress = g_sBNFromAddress
oMessage.Subject = MessageSubject
oMessage.AddRecipient MessageRecipientName, MessageRecipientAddress
oMessage.Body = "The Following Errors have occured." & vbNewLine & vbNewLine & s
oMessage.Save
End If