kacalapy
kacalapy

Reputation: 10154

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#/ .net 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?

Upvotes: 2

Views: 401

Answers (2)

HungryHippos
HungryHippos

Reputation: 1543

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?

Upvotes: 1

user1251108
user1251108

Reputation:

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/

Upvotes: 0

Related Questions