can i use .net to get email address from exchange (not AD) using username?
is there a way to get at the exchange data store? i want to pull the email address of users in my c#/ .ne开发者_JAVA百科t application - preferably using user names.
i am doing this in AD but the email addresses in AD are wrong and i get bounce backs. seeing how unreliable AD is with Emails i need to go to exchange as my only saving grace.
any clue?
I am mainly a PowerShell user but when I do this I utilise the System.DirectoryServices.DirectorySearcher .NET method, like this:
# Bind to OU Container
$OUPath = "LDAP://OU=SomeContainer,DC=domain,DC=com"
$SearchOU = [ADSI]$OUPath
# Use System.DirectoryServices.DirectorySearcher to Find objects in Container
$Searcher = New-Object System.DirectoryServices.DirectorySearcher($SearchOU)
# Filter results
$LDAPQueryFilter = "(&(HomeMDB=*)(mail=*)(objectClass=user))"
$Searcher.Filter = $LDAPQueryFilter
# Return results
$SearchResults = $Searcher.FindAll()
As someone else mentioned you want to enumerate the ProxyAddresses collection which is an AD field with a multi-valued property (it's an array of strings basically).
Hope this helps a bit?
As the other responses have indicated, all versions of Exchange through Exchange 2010 read and write user data directly in Active Directory. There is no other repository. Even Exchange Online reads and writes data to AD under the covers. I would recommend double-checking AD attribute you're using to read the email address.
If you would prefer to avoid the AD query directly, you may use EWS to make the AD query: http://vivekiyer.net/2010/07/17/querying-the-global-address-list-gal-via-exchange-web-services-ews/
精彩评论