Is there any easy/elegant way to verify, that a SMTP address is associated with an Exchange mailbox via EWS?
Credentials of an administrative Exchange user are given.
Problem:
Not that elegant to compare the exception message
Takes about 200-250ms per user (not parallel)
Another Problem:
It is possible, that there are contacts in the GAL, that don't have a mailbox.
So ResolveNames won't be helpful.
The easiest way is to use the ResolveName operation and search the Directory you just need to prefix the address with smtp: and Exchange will the search both the Primary and proxyaddressses eg
String EmailAddresstoCheck = "info@domain.com";
NameResolutionCollection ncCol = service.ResolveName(("SMTP:" + EmailAddresstoCheck), ResolveNameSearchLocation.DirectoryOnly, true);
if (ncCol.Count == 1)
{
if (ncCol[0].Contact != null)
{
if (EmailAddresstoCheck.ToLower() == ncCol[0].Mailbox.Address)
{
Console.WriteLine("Primary SMTP Address of " + ncCol[0].Contact.DisplayName);
}
else
{
Console.WriteLine("Proxy Address of " + ncCol[0].Contact.DisplayName);
Console.WriteLine("Primary SMTP Address : " + ncCol[0].Mailbox.Address);
}
}
}
Cheers Glen