EmailLogs.vbs
Option Explicit
Dim iMsg, iConf, Flds, pc 'Email vars
Dim logFile, maxLogSize 'Log vars
Dim FSO, File, strSize 'File size vars
'by mReschke
logFile = "C:\Logs\somelog.log"
maxLogSize = 6 'in MB
Set FSO = CreateObject("Scripting.FileSystemObject")
if FSO.FileExists(logFile) Then
Set File = FSO.GetFile(logFile)
strSize = File.Size / 1024 / 1024 'Now in MB
Call SendLogEmail
End If
' ---------------------------------------------------------------------------------
Sub SendLogEmail()
Set pc = CreateObject("Wscript.Network")
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
dim emailBody
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "xxx.xxx.xxx.xxx"
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "smtpauthenticate") = 0
'Flds.Item(schema & "sendusername") = "domain\username"
'Flds.Item(schema & "sendpassword") = "pass"
Flds.Item(schema & "smtpusessl") = 0
Flds.Update
With iMsg
.To = "you@mail.com,you2@mail.com"
.From = "Your Log "
if strSize <= maxLogSize Then
.Subject = pc.ComputerName & " log"
.AddAttachment(logFile)
emailBody = "Production Log for " & pc.ComputerName & ""
Else
.Subject = pc.ComputerName & " log too big"
emailBody = "Log file for " & pc.ComputerName & " is greater than " & maxLogSize & "MB. It is " & strSize & "MB"
End If
.HTMLBody = emailBody
.Sender = "Your Log "
.Organization = "Your Company"
.ReplyTo = "replyhere@mail.com"
Set .Configuration = iConf
.Send
End With
' Release Interfaces
Set iMsg = nothing
Set iConf = nothing
Set Flds = nothing
End Sub