Set adoConnection = CreateObject("ADODB.Connection")
Set adoCommand = CreateObject("ADODB.Command")
adoConnection.Provider = "ADsDSOOBject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strDomain = Replace(strDNSDomain, ",DC=",".")
strDomain = Replace(strDomain, "DC=","")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strFilter = "(objectCategory=computer)"
strAttributes = "displayName,userAccountControl,mail"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set oDomain = GetObject("LDAP://" & strDNSDomain)
Set winLossVal = oDomain.Get("WinEvent.Solitaire.Streak")
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
Sub sendEmail(strEmail, solitaireWinLoss, msgFlag, Name, domain)
Accept input parameters
Dim email
Dim strMessage
Dim strName
Dim strDomain
Dim strMesagept2
email= strEmail
strMessage= msgFlag
strName = Name
strDomain = domain
If strMessage=1 then
strMessage="has just won "
strMessage2= "Solitaire Champion"
ElseIf strMessage=0 Then
strMessage="has just lost "
strMessage2= "Solitaire Loser"
End If
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Message Alert from Domain Administrator: " & strMessage2
objMessage.From = EMAIL_FROM
objMessage.To = email
objMessage.TextBody = "Hello Everybody!" & strName & ", has just finished a game of Solitaire! The outcome of the game was: "& VbCrLf & VbCrLf _
& solitaireWinLoss & VbCrLf & VbCrLf
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = EMAIL_SERVER
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "youruserid"
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "yourpassword"
'Server port number(typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End Sub