Get user's Exchange server and email address in .NET

送分小仙女□ 提交于 2019-12-30 07:05:09

问题


H​i. I would like to know the address of my user's Exchange server (assuming she's in a typical Windows office network). This is in a C# application.


I already have the user's email address, I found it at System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress, after referencing System.DirectoryServices.AccountManagement


回答1:


I use this for my Exchange client application.

  1. Install Exchange Web Services Managed API
  2. Change your C# project's Properties/Application changed the target framework to '.NET Framework 4' not '.NET 4 Client Profile'
  3. Reference C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll

Now code:

var exchange = new ExchangeService();
exchange.AutodiscoverUrl(from);
var server = exchange.Url.Host;
Console.WriteLine(server);

Here's the MSDN documentation. but note it's for the unreleased version 1.2 of the API. I can't locate the documentation for version 1.1




回答2:


You're looking for the AD attribute called homeMDB: http://msdn.microsoft.com/en-us/library/ms980583(v=exchg.65).aspx

I don't think there is a nice .NET wrapper for this attribute, so you'll need to use a lower-level LDAP API to get it.

Note that with later versions of Exchange (i.e. 2010) you can connect to any CAS role and Exchange will figure out the routing.




回答3:


Have you looked into using autodiscover? http://technet.microsoft.com/en-us/library/bb124251.aspx



来源:https://stackoverflow.com/questions/9705951/get-users-exchange-server-and-email-address-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!