在微软的Exchange C#中列出的所有电子邮件地址 [英] C# List all email addresses in MS Exchange

查看:260
本文介绍了在微软的Exchange C#中列出的所有电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Exchange /活动目录的所有电子邮件的列表。
是否喜欢j.doe@domain.com或电子邮件组像所有接触或CEO,他们包括几个电子邮件地址的邮件。
这是我的code到目前为止:

 的DirectoryEntry德=新的DirectoryEntry(ad_path);
DirectorySearcher从DS =新DirectorySearcher从(日);
ds.Filter =(及(对象类= addressBookContainer)(CN =所有全局地址列表,CN =地址列表容器,CN =第一个组织,CN = Microsoft Exchange时,CN =服务,CN =配置,DC = MYDOMAIN,DC =局部));
SearchResultCollection SS = ds.FindAll(); //数= 0
 

解决方案

您将不能获得Mailadresses这些目录的直接对象,这些都只是配置对象。如果你只是想获得的所有Mailadresses在你的组织,你可以简单地查询以下(注意,默认情况下有限resultsize):

 的DirectoryEntry德=新的DirectoryEntry();
        DirectorySearcher从DS =新DirectorySearcher从(日);
        ds.PropertiesToLoad.Add(代理地址);
        ds.Filter =(及(代理地址= SMTP:*));
        SearchResultCollection SS = ds.FindAll(); //数= 0

        的foreach(在SS信息搜索结果SR)
        {//你仍然可能需要过滤掉其他addresstypes,例如:SIP:
            的foreach(字符串地址在sr.Properties [代理地址])
                Console.WriteLine(地址);
//或者在内部消除SMTP:preFIX Console.WriteLine(addr.SubString(5));

        }
 

如果您想获得具体的交换地址表中的内容,您可以修改您的过滤器,并与该列表中的purportedSearch'-属性的值替换,例如:

<$p$p><$c$c>(&(mailNickname=*)(|(objectClass=user)(objectClass=contact)(objectClass=msExchSystemMailbox)(objectClass=msExchDynamicDistributionList)(objectClass=group)(objectClass=publicFolder)))

这是默认全局地址列表默认筛选器。或者你可以枚举所有AddressBookContainer对象(CN =所有全局地址列表,CN =地址列表容器,CN =第一个组织,CN = Microsoft Exchange时,CN =服务,CN =配置,DC = MYDOMAIN,DC =本地) 做一个查询与每个purportedSearch'-属性。

I need to get list of all emails from exchange/active directory.
Whether emails like j.doe@domain.com or email groups like all-contacts or CEO which they includes couple of email addresses.
this is my code so far:

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

解决方案

You will not get the Mailadresses out of these Directory Objects directly, these are only configuration objects. If you simply want to get all Mailadresses in your org you could simply query the following (note that there is a limited resultsize by default):

        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 whithout the 'smtp:' prefix Console.WriteLine(addr.SubString(5));

        }

If you would like to get the contents of specific exchange address lists, you can modify your filter and replace it with the value of the 'purportedSearch'-Property of that list, for example:

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

which is the default Filter for "Default Global Address List". Or you can enum all AddressBookContainer objects in (CN=All Global Address Lists,CN=Address Lists Container,CN=First Organization,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=mydomain,DC=local) to do a query with each 'purportedSearch'-Property.

这篇关于在微软的Exchange C#中列出的所有电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆