This script will email a log file (or any file specified) only if the file is under a certain size. If the file is over that size limit, it will still email, but no log will be attached. See Send Email using VBScript
Script does not use parameters, everything is hard coded, so just call the .vbs. Great in a scheduled task to email you a daily log file. Can easily be modified with parameters for various purposes.
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