Ok guys I need something done with this script, and simply don't have the time to deal with it at the moment. Currently the script below will scan a robocopy log, attach it to an email, and in the email body post rather it was successful or had errors......
What I would like for it to do, is basically the same thing, but I do not want it to attach the log unless it had errors. So if it is successful, I simply want an email saying that it was successful, no log attached; if it failed, then I want to keep the error message in the subject line, and want it to attach the log......I would also like it to change the subject line, if it was successful then the subject should state Data Copy Successful, if it failed then Data Copy Unsuccessful, etc.
Dim txtSMTPServer, txtTo, txtFrom, txtSubject, txtBody
Dim txtLog, strValue, iTotal, iPos, strText
txtSMTPServer = "server.domain.local" 'SMTP server
txtTo = "email@example.com" 'To Address
txtFrom = "firstname.lastname@example.org" 'From Address
txtSubject = "Data Backup Status" 'Subject line
txtLog = "c:\robo.log" 'path to the
'robocopy log file
'Get the file contents
FileContents = GetFile(txtLog)
'-- Cycle thru the log file to find errors --
strText = FileContents
iPos = 1
Do While iPos <= Len(strText)
If InStr(iPos, UCase(strText), "0X00000") > 0 Then
iTotal = iTotal + 1
iPos = InStr(iPos, UCase(strText), "0X00000")_
If iTotal > 0 Then
strErrors = 1
strErrors = 0
'Output something meaningful if we do or dont find failures
If strErrors = 1 Then
txtBody = "DETECTED A FAILURE " & iTotal & " files " &_
"appear to have failed in this job. See attached file."
txtBody = "ROBOCOPY SUCCESSFUL no errors seem to be " &_
"present in this robocopy log. See attached file."
'-- Email Send --
Const cdoSendUsingMethod = _
cdoSendUsingPort = 2, _
cdoSMTPServer = _
'// Create CDO connections.
Dim iMsg, iConf, Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = txtSMTPServer
'// Set the message properties.
Set .Configuration = iConf
.To = txtTo
.From = txtFrom
.Subject = txtSubject
.TextBody = txtBody
if txtlog <> "" then iMsg.AddAttachment txtLog
'// Send the message.
iMsg.Send ' send the message.
'-- Readfile function --
If txtLog<>"" Then
Dim FS, FileStream
Set FS = CreateObject("Scripting.FileSystemObject")
on error resume Next
Set FileStream = FS.OpenTextFile(txtLog)
GetFile = FileStream.ReadAll