locked
EWS API service.ResolveName problem RRS feed

  • Question

  • Hi,

    My app needs user profile details like DisplayName, profile Image ( if exists ), User status ( Offline, online )and the user message like "What's on your mind"

    Problem :  I used ExchangeService.ResolveName and retrieved the details. But the ItemId of the contacts is always Null. So, when I use it further I get an exception
      NameResolutionCollection matchingnames = service.ResolveName("X@X.com", ResolveNameSearchLocation.DirectoryOnly, true);
                foreach (NameResolution item in matchingnames)
                {
    
                }

    I am always settings returncontactdetails = true so that I get full contact details.

    But I don't get all details, even if the profile has picture, I don't get one.

    Is there something I am missing ??

    Wednesday, November 21, 2012 2:47 PM

All replies

  • I'm not sure what you're trying to do.  But, if you are trying to get contacts using EWS, here is some sample code I've used:

    The following code dumps the contact book of a connected mailbox:

    FindItemsResults<Item> contactItems = service.FindItems(WellKnownFolderName.Contacts,

                                                            new ItemView(int.MaxValue));

    EmailAddressKey[] emailAddressKeys = { EmailAddressKey.EmailAddress1,

                                           EmailAddressKey.EmailAddress2,

                                           EmailAddressKey.EmailAddress3 };

    foreach (Contact contact in contactItems.Items)

    {

       console.write("DisplayName=" + contact.DisplayName);

       foreach (EmailAddressKey emailAddressKey in emailAddressKeys)

       {

          if (contact.EmailAddresses.Contains(emailAddressKey) == true)

          {

             emailAddress = contact.EmailAddresses[emailAddressKey];

             if (emailAddress.Name != null)

                console.write("Email=" + emailAddress.Address.ToString());

             else

                console.write("Email=" + emailAddress.Name  +

                              “<” + emailAddress.Address.ToString() + “>”);

           }

       }//foreach email address

       Console.write(contact.Id.UniqueId.ToString());

       Console.write(“”);

     }//foreach contact

    The following code dumps a distribution list in an address book on a connected server:

    NameResolutionCollection nameResolutions = service.ResolveName(strDistributionList,

                                         ResolveNameSearchLocation.DirectoryOnly, true);

    ExpandGroupResults groupResults = null;

    foreach (NameResolution nameResolution in nameResolutions)

    {

        groupResults = service.ExpandGroup(nameResolution.Mailbox.Address);

        foreach (EmailAddress member in groupResults.Members)

        {

            Console.write(member.Name + " <" + member.Address + ">");

        }//foreach contact

    }//foreach distribution list

    Wednesday, November 21, 2012 6:43 PM
  • Hi Andy,

    Thanks for your reply

    My problem is I have a contact which is not in mycontacts folder and need to retrieve using ResolveName from directory.

    If I want to dig into the contact details of this user. I must get his ItemId. But when I search object returned through ResolveName and extract the Contact field from NameCollectionItem. contact -> ItemId is always Null

    Actually I need a profile picture of the contact searched returned from ResolveName from directory. Do you know any way how to get details of contact which is not from the Contacts folder ?


    • Edited by CaptainHawk Thursday, November 22, 2012 2:30 AM
    Thursday, November 22, 2012 2:29 AM
  • My experiences with ResolveName are quite similar: even if you specify a ExtentedPropertyDefinition for additional MAPI properties (in my case it's an extension attribute) you will not receive this data from the GAL.

    The following code will find the SMTP address in the GAL but won't return the MAPI property value (extensionAttribute15).

    exchangeService.ResolveName("SMTP:" + primarySmtpAddress,
       ResolveNameSearchLocation.DirectoryOnly,
       true,
       new ExtendedPropertyDefinition(0x85C9,
                    MapiPropertyType.String)));

    The workaround might be to directly access the GAL in the AD, e.g.

    NameResolutionCollection nrc = 
       exchangeService.ResolveName(
          "SMTP:" + primarySmtpAddress,
          ResolveNameSearchLocation.DirectoryOnly,
          true,
          new PropertySet(ContactSchema.DirectoryId));
    foreach (NameResolution nr in nrc)
    {
       string guidstr = nr.Contact.DirectoryId;
       DirectoryEntry directoryEntry =
          new DirectoryEntry("GC://"+guidstr);
       // ... access e.g. "photo"

    But this won't work within a mail app. An improved version of ResolveName (with Contact object support also from the GAL and not only from the Contacts folder within the user's mailbox) would be nice. There is no address book support in EWS as far as I know.  In MAPI it would be IAddrBook and IMailUser.

     





    • Edited by NielsS Wednesday, January 9, 2013 10:17 AM
    Wednesday, January 9, 2013 10:01 AM