0
votes

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.

The following quick and dirty solution works:
Create an ExchangeService with the SMTP address as Impersonated user
Try to make a method call
When the exception message is "The SMTP address has no mailbox associated with it.", the SMTP address is not associated with a mailbox

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.

1

1 Answers

0
votes

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 = "[email protected]";
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