Stephan van Rooij

Software architect with a passion for home automation.

Resolve exchange alias to SMTP address

R

When working with Exchange, you’ll sometimes need the primary address and not some kind of alias. This snippet helps you with that.

You’ll off course need the Microsoft Exchange Webservice dll, but that is just a simple package on nuget.

var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://serv/EWS/exchange.asmx");
service.Credentials = new NetworkCredential("001234", "PasswordForUser001234", "Domain");

//Never use this part in production!!
//ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
//    {
//        return true;
//    };

var resolvedNames = service.ResolveName("001234");
foreach (var resolvedName in resolvedNames)
{
    Console.WriteLine(resolvedName.Mailbox.Address);
}

//FOUND on: http://stackoverflow.com/questions/6081243/get-logged-on-users-smtp-address-via-ews
Like what you're seeing? Consider Sharing on Twitter or Sponsoring me