Using the Exchange Web Services API, is it possible to determine whether a mailbox/e-mail address such as *someone@mydomain.com* exists within an organization?

If so, which is the simplest way to do this and is it possible without the use of impersonation?

**Case:** A Windows Service regularly sends e-mails to people within the organization. It does not have any explicit knowledge about their e-mail adresses. It only knows their username and assumes that their e-mail address is *username*@mydomain.com. This is true for all users except for a few that do not have mailboxes. In these cases, it should not attempt to send the e-mail in the first place.

Solution:
---------

As suggested by [mathieu](https://stackoverflow.com/a/11629697/137471): look for user and e-mail address in Active Directory instead. This function gets the job done:

```
using System.DirectoryServices.AccountManagement;
// ...

public static bool TryGetUserEmailAddress(string userName, out string email)
{
  using (PrincipalContext domainContext = 
    new PrincipalContext(ContextType.Domain, Environment.UserDomainName))
  using (UserPrincipal user = 
    UserPrincipal.FindByIdentity(domainContext, userName))
  {
    if (user != null && !string.IsNullOrWhiteSpace(user.EmailAddress))
    {
      email = user.EmailAddress;
      return true;
    }
  }
  email = null;
  return false; // user not found or no e-mail address specified
}

```