交换中公用文件夹的电子邮件地址列表 [英] List of email address to public folders in exchange

查看:203
本文介绍了交换中公用文件夹的电子邮件地址列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取用于交换公用文件夹的所有电子邮件地址的列表?

How do i get a list of all e-mail address for exchange public folders?

我将自己答复,将接受所提供的最佳答复.

Will reply on my own, will accept the best reply offered.

推荐答案

虽然您以自己的答案发布的内容行之有效,但有助于您阅读用于了解其局限性的方法和对象的文档.如果多次调用此代码,最终将导致内存泄漏. foreach语句不会在使用的对象上调用Dispose(),只会调用它创建的枚举器.下面是搜索目录的一种更好的方法(尽管很少进行错误检查并且没有异常处理).

While what you posted as your own answer would work, it helps to read the documentation for the methods and objects you are using to understand their limitations. If you had called this code multiple times you would eventually had a memory leak on your hands. The foreach statement doesn't call Dispose() on the object used, only the enumerator it creates. Below is a somewhat better method of searching the directory (though very little error checking and no exception handling).

public static void GetPublicFolderList()
{
    DirectoryEntry entry = new DirectoryEntry("LDAP://sorcogruppen.no");
    DirectorySearcher mySearcher = new DirectorySearcher(entry);
    mySearcher.Filter = "(&(objectClass=publicfolder))";
    // Request the mail attribute only to reduce the ammount of traffic
    // between a DC and the application.
    mySearcher.PropertiesToLoad.Add("mail");

    // See Note 1
    //mySearcher.SizeLimit = int.MaxValue;

    // No point in requesting all of them at once, it'll page through
    // all of them for you.
    mySearcher.PageSize = 100;

    // Wrap in a using so the object gets disposed properly.
    // (See Note 2)
    using (SearchResultCollection searchResults = mySearcher.FindAll())
    {
        foreach (SearchResult resEnt in searchResults)
        {
            // Make sure the mail attribute is provided and that there
            // is actually data provided.
            if (resEnt.Properties["mail"] != null
                 && resEnt.Properties["mail"].Count > 0)
            {
                string email = resEnt.Properties["mail"][0] as string;
                if (!String.IsNullOrEmpty(email))
                {
                    // Do something with the email address
                    // for the public folder.
                }
            }
        }
    }
}

注释1

DirectorySearcher.SizeLimit 表示如果大小限制大于服务器确定的默认值(1000个条目),则忽略该大小限制.通过分页,您可以根据需要获取所有需要的条目.

Note 1

The remarks for DirectorySearcher.SizeLimit indicate that the size limit is ignored if it is higher than the server-determined default (1000 entries). Paging allows you to get all of the entries you need as you need them.

DirectorySearcher.FindAll()提到需要处置SearchResultCollection来释放资源.将其包装在using语句中可以清楚地表明您是程序员的意图.

The remarks for DirectorySearcher.FindAll() mention that the SearchResultCollection needs to be disposed to release resources. Wrapping it in a using statement clearly identifies your intent as a programmer.

如果您使用的是Exchange 2007或2010,则还可以安装Exchange管理工具并使用powershell cmdlet查询公用文件夹.您可以实用地创建一个Powershell运行空间并直接调用Exchange cmdlet,而实际上不需要用户进行交互的控制台.

If you're using Exchange 2007 or 2010 you could also install the Exchange Management Tools and use the powershell cmdlets to query your public folders. You can pragmatically create a powershell runspace and call the Exchange cmdlets directly without actually needing a console for the user to interact with.

这篇关于交换中公用文件夹的电子邮件地址列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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