csharp 从AD #exchange下载所有代理地址

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 从AD #exchange下载所有代理地址相关的知识,希望对你有一定的参考价值。

 public void getAllProxyAddresses()
        {
            var db = new UMTDataContext();

            PrincipalContext AD = new PrincipalContext(ContextType.Domain, this.MailDomain);
            UserPrincipal u = new UserPrincipal(AD);
            PrincipalSearcher search = new PrincipalSearcher(u);


            List<string> emailAddresses = new List<string>();

            Console.WriteLine("Huidige collectie aan het verwijderen.");

            db.ExecuteCommand("truncate table ProxyAddress");


            db.SubmitChanges();

            Console.WriteLine("Alle proxy addressen aan het verzamelen.. dit duurt wel even.");


            foreach (UserPrincipal result in search.FindAll())
            {

                PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "headquarters");
                UserPrincipal user = UserPrincipal.FindByIdentity(domainContext, result.SamAccountName);

                // Add the "mail" entry
                emailAddresses.Add(user.EmailAddress);

                // Add the "proxyaddresses" entries.
                System.DirectoryServices.PropertyCollection properties = ((DirectoryEntry)user.GetUnderlyingObject()).Properties;
                foreach (object property in properties["proxyaddresses"])
                {
                    emailAddresses.Add(property.ToString());
                }
            }
            Console.WriteLine("Alle proxy addressen zijn verzameld. Nu in de database inserten.");
            search.Dispose();

            foreach (var e in emailAddresses)
            {
                var mail = new ProxyAddress();
                mail.Mail = e;
                db.ProxyAddresses.InsertOnSubmit(mail);
            }

            db.SubmitChanges();
            Console.WriteLine("{0} proxyadressen toegevoegd", db.ProxyAddresses.Count());
            Console.WriteLine("Klaar met deze bevalling.");

        }

以上是关于csharp 从AD #exchange下载所有代理地址的主要内容,如果未能解决你的问题,请参考以下文章

AD账号及Exchange 邮箱的误删除恢复

KeyMob:打造国内领先的移动Ad Exchange平台

Exchange传输规则概要

AD与Exchange升级系列

AD读取Excel新建客户邮箱的测试环境部署有感

安装Exchange 2013后AD中有什么变化