Les Snippets

Connexion

Obtenir la liste e-mail de tout les utilisateurs d'un domaine

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 03/10/2008 20:32:03 et initié par Willi [Liste]
Vue : 41503
Catégorie(s) : Système
Langages dispo pour ce code :
- C# 1.x, VB 2005, VB 2008, VB.NET 1.x
- C# 1.x, C# 2.x, C# 3.x



Langage : VB.NET 1.x , VB 2005 , C# 1.x , VB 2008
Date ajout : 03/10/2008
Posté par Willi [Liste]
Public Function GetMailsListOfAllUsers(ByVal domain As String) As String() 
Dim colEntry As New Collections.Generic.List(Of String) 
Dim entry As New DirectoryEntry(String.Format("LDAP://{0}", domain)) 
entry.AuthenticationType = AuthenticationTypes.Secure 
Dim ds As New DirectorySearcher(entry) 
ds.Filter = "(&(objectClass=User))" 
Dim results As SearchResultCollection = ds.FindAll() 
For Each res As SearchResult In results 
Try 
Dim dire As DirectoryEntry = res.GetDirectoryEntry() 
colEntry.Add(dire.Properties("mail").Value.ToString()) 
Catch ex As Exception 
Continue For 
End Try 
Next 
Return colEntry.ToArray() 
End Function

Remarque :
Ajouter la référence à l'assembly System.DirectoryServices

Puis ajouter la directive:
Imports System.DirectoryServices

Exemple d'utilisation:
Dim mailsOfAllUsers as string() = GetMailsListOfAllUsers("MonDomaine.fr")
Langage : C# 1.x , C# 2.x , C# 3.x
Date ajout : 03/10/2008
Posté par Willi [Liste]
public string[] GetMailsListOfAllUsers(string domain)
{
  Collections.Generic.List<string> colEntry = new Collections.Generic.List<string>();
  DirectoryEntry entry = new DirectoryEntry(string.Format("LDAP://{0}", domain));
  entry.AuthenticationType = AuthenticationTypes.Secure;
  DirectorySearcher ds = new DirectorySearcher(entry);
  ds.Filter = "(&(objectClass=User))";
  SearchResultCollection results = ds.FindAll();
  foreach (SearchResult res in results) {
    try {
      DirectoryEntry dire = res.GetDirectoryEntry();
      colEntry.Add(dire.Properties["mail"].Value.ToString());
    }
    catch (Exception ex) {
      continue;
    }
  }
  return colEntry.ToArray();
}
Remarque :
Ajouter la référence à l'assembly System.DirectoryServices

Puis ajouter la directive:
using System.DirectoryServices;

Exemple d'utilisation:
string[] mailsOfAllUsers = GetMailsListOfAllUsers("MonDomaine.fr") ;

Snippets en rapport avec : Directory, Mail, Domaine, Ad, Active



Codes sources en rapport avec : Directory, Mail, Domaine, Ad, Active

{PHP} AUTHENTIFICATION LDAP | AD 2003SERVEUR
Je pense que je ne suis pas le premier à me prendre la tête sur l'authenfication Ldap Après avoir...

{ASP / ASP.NET} RÉCUPÉRATION DES GROUPES AD D'UN USER EN ASPNET
Tout est dans le titre ;-)...

{Visual Basic, VB6, VB.NET, VB 2005} SIGNATURE STANDARDISÉE DANS OUTLOOK VIA PARAMÈTRES ACTIVE DIRECTORY DE L'UTILISATEUR
Ecriture d'une signature pour Outlook (2002 et 2003 testés) afin que tous les utilisateur d'une même...

{Flash} FORMULAIRE MAIL
un petit exemple pour les gens qui ont besoin de créer un formulaire de contact par exemple pour le...

{Python} SCANNER D' ADRESSES MAILS (ENTREPRISES, MESSAGERIES, BOITE MAIL...) EX : HOTMAIL, YAHOO, FREE...
J'ai repris ce code d' un logiciel Gnu qui sert à se renseigner sur les e-mails des companies du sty...

{Visual Basic, VB6, VB.NET, VB 2005} [ACTIVE DIRECTORY] AJOUT UTILISATEURS VIA EXCEL.VBS
Comme sont nom l'indique, ce script permet d'ajouter autant d'utilisateur dans active directory qu'i...

{Visual Basic, VB6, VB.NET, VB 2005} EXPLORER LDAP ACTIVE DIRECTORY DANS UN TREEVIEW
Cette interface utilise l'objet treeview pour explorer Active Directory, elle inclus également une o...

{PHP} CONNEXION LDAP AVEC LOGIN MOT DE PASSE EN PHP
ce code permet de verifier l'identité d'une personne se connectant a un annuaire LDAP ( dans mon cas...

{C# / C#.NET} ACTIVE DIRECTORY : AJOUT D'UN UTILISATEUR, PASSWORD, ACTIVATION ET AJOUT DANS UN GROUPE
Le titre se suffit certainement à lui même mais bon. Devant refaire le systéme d'inscription du Cl...

{PHP} CLASSE DE VÉRIFICATION DE DONNÉES
cette classe réunies plusieurs vérifications de données que je fais souvent pour mes sites : vérific...