【问题标题】:C# List all email addresses in MS ExchangeC# 列出 MS Exchange 中的所有电子邮件地址
【发布时间】:2014-09-01 09:35:31
【问题描述】:

我需要从交换/活动目录中获取所有电子邮件的列表。
无论是像 j.doe@domain.com 这样的电子邮件还是像 all-contacts 或 CEO 这样的电子邮件组,它们都包含几个电子邮件地址。
到目前为止,这是我的代码:

DirectoryEntry de = new DirectoryEntry(ad_path);
DirectorySearcher ds = new DirectorySearcher(de);
ds.Filter = "(&(objectClass=addressBookContainer)(CN=All Global Address Lists,CN=Address Lists Container,CN=First Organization,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=mydomain,DC=local))";
SearchResultCollection ss = ds.FindAll(); // count = 0

【问题讨论】:

    标签: c# active-directory exchange-server-2010


    【解决方案1】:

    您不会从目录对象中获取电子邮件地址,因为这些只是配置对象。如果您想获取组织中的所有邮件地址,您可以查询以下内容(请注意,默认情况下结果大小有限):

            DirectoryEntry de = new DirectoryEntry();
            DirectorySearcher ds = new DirectorySearcher(de);
            ds.PropertiesToLoad.Add("proxyAddresses");
            ds.Filter = "(&(proxyAddresses=smtp:*))";
            SearchResultCollection ss = ds.FindAll(); // count = 0
    
            foreach (SearchResult sr in ss)
            {
                // you might still need to filter out other addresstypes, ex: sip:
                foreach (String addr in sr.Properties["proxyAddresses"])
                    Console.WriteLine(addr);
                //or without the 'smtp:' prefix Console.WriteLine(addr.SubString(5));
    
            }
    

    如果您想获取特定交换地址列表的内容,您可以修改您的过滤器并将其替换为该列表的“purportedSearch”属性的值,例如:

    (&(mailNickname=*)(|(objectClass=user)(objectClass=contact)(objectClass=msExchSystemMailbox)(objectClass=msExchDynamicDistributionList)(objectClass=group)(objectClass=publicFolder)))
    

    这是“默认全局地址列表”的默认过滤器。

    您还可以枚举 (CN=All Global Address Lists,CN=Address Lists Container,CN=First Organization,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=mydomain,DC=local 中的所有 AddressBookContainer 对象) 对每个 'purportedSearch'-Property 进行查询。

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 2013-07-26
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2012-06-24
      • 1970-01-01
      • 2010-09-19
      • 2023-03-18
      相关资源
      最近更新 更多