Here is the code that emails each user in the AD group.
Function SMTPGroupTemplate(ByVal K2 As ClientEventContext, ByVal strADGroup As String)
'To be called from Client Event
'Purpose: Emails each member in the AD group
Dim group_entry As New System.DirectoryServices.DirectoryEntry("LDAP://CN=" & strADGroup & ",OU=yourcompany User Groups,DC=yourcompany,DC=Com")
Dim strGroup_member As String
Dim entry As New System.DirectoryServices.DirectoryEntry
Dim searcher As New System.DirectoryServices.DirectorySearcher
Dim result As System.DirectoryServices.SearchResult
Dim sEmail As String = String.empty
For Each strGroup_member In group_entry.Properties("member")
entry = New System.DirectoryServices.DirectoryEntry("LDAP://" & strGroup_member)
searcher = New System.DirectoryServices.DirectorySearcher(entry)
searcher.PropertiesToLoad.Add("mail")
result = searcher.FindOne
If Not result Is Nothing Then
Try
sEmail = result.Properties("mail")(0).ToString()
SMTPFunction(K2, sEmail)
Catch ex As exception
'suppress error in case AD user does not have email address
End Try
End If
Next
End Function
+10
Hi,
Technically it will be possible to get the members of the group by using the DSHelper, but because this is used internally in K2.net it is not supported and also not recommended that you use it.
Using .Net functions to return the list of users will work.
To get the code to work I would suggest that you look through MSDN on the exact way to get the members of a group.
Regards,
JohanL
Technically it will be possible to get the members of the group by using the DSHelper, but because this is used internally in K2.net it is not supported and also not recommended that you use it.
Using .Net functions to return the list of users will work.
To get the code to work I would suggest that you look through MSDN on the exact way to get the members of a group.
Regards,
JohanL
+5
Hi,
Just for some extra info...
Peter's code would work with non-nested groups, but as soon as you might have some nested groups you would just have to modify the code to load also the objectClass property and test if the object is a 'group' or 'person'. Obviously recursion would have to come in play when working with nested groups.
Cheers
Just for some extra info...
Peter's code would work with non-nested groups, but as soon as you might have some nested groups you would just have to modify the code to load also the objectClass property and test if the object is a 'group' or 'person'. Obviously recursion would have to come in play when working with nested groups.
Cheers
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.