objEmail.From = "[email protected]"
objEmail.To = "[email protected]"
objEmail.Subject = "List of Users in Old Users OU"
objEmail.Textbody = "Please find the List of Users in Old Users OU in this email as an attachment"
'-------------------Get Date In yyyyMMDD format ------------------START
Function GetFormattedDate
strDate = CDate(Date)
strDay = DatePart("d", strDate)
strMonth = DatePart("m", strDate)
strYear = DatePart("yyyy", strDate)
If strDay < 10 Then
strDay = "0" & strDay
End If
If strMonth < 10 Then
strMonth = "0" & strMonth
End If
GetFormattedDate = strYear & strMonth & strDay
End Function
MsgBox GetFormattedDate
'-------------------Get Date In yyyyMMDD format ------------------END
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\scripts\Ad stale cleanup project\month1day30\ComputersWithException.xlsx" , "C:\scripts\Ad stale cleanup project\month1day30\ComputersWithException_"& GetFormattedDate &".xlsx"
objEmail.AddAttachment "C:\scripts\Ad stale cleanup project\month1day30\ComputersWithException_"& GetFormattedDate &".xlsx"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"SMTPSERVERNAME.Domain.com"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send