2015年5月11日 星期一

用ExchangeService API (EWS) 確認EMAIL信箱位址是否存在

            string sResult = "";
            List<string> emailCollect = new List<string>();
            ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            es.Credentials = new System.Net.NetworkCredential("ACCOUNT", "PASSWORD", "NETAREA");
            es.Url = new Uri("https://MYWEBSITE/ews/Exchange.asmx");
            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            var resolvedNames = es.ResolveName("想找的姓名或帳號");

            foreach (var resolvedName in resolvedNames)
            {
                emailCollect.Add(resolvedName.Mailbox.Address);
            }
            if (emailCollect.Count > 0)
            {
                sResult = emailCollect[0].ToString().Trim();
                Console.WriteLine(sResult);
            }
            else
                Console.WriteLine("找不到信箱!");

沒有留言:

張貼留言