EWS Managed API 1.1 - How to get mail address of mailbox owner of some item

Unanswered EWS Managed API 1.1 - How to get mail address of mailbox owner of some item

  • Friday, September 09, 2011 7:11 PM
     
     

    Hi!

    I retrieve a task through the webservices by its ID (using Task.Bind()) and I would like to know what the mail address of the mailbox containing the task is. How can I get it? I was looking for ways to get the mailbox through the parent folder id, which does not seem to be possible.

    Regards,
    Oliver Hanappi 

All Replies

  • Tuesday, September 13, 2011 3:11 AM
     
      Has Code

    You should be able to get the X500 address out of the PR_STORE_ENTRYID and then use this in a ResolveName operation to get the SMTP Address and displayname of the mailbox. eg I use the following

               Item itItem = Item.Bind(service, ((AlternateId)cvtresp[0].ConvertedId).UniqueId);
                ExtendedPropertyDefinition PR_STORE_ENTRYID = new ExtendedPropertyDefinition(4091, MapiPropertyType.Binary);
                PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_STORE_ENTRYID };
                itItem.Load(psPropSet);
                object propVal = null;
                if (itItem.TryGetProperty(PR_STORE_ENTRYID, out propVal))
                {
    
                    byte[] ssStoreID = (byte[])propVal;
                    int leLegDnStart = 0;
                    String lnLegDN = "";
                    for (int ssArraynum = (ssStoreID.Length - 2); ssArraynum != 0; ssArraynum--)
                    {
                        if (ssStoreID[ssArraynum] == 0)
                        {
                            leLegDnStart = ssArraynum;
                            lnLegDN = System.Text.ASCIIEncoding.ASCII.GetString(ssStoreID, leLegDnStart + 1, (ssStoreID.Length - (leLegDnStart + 2)));
                            ssArraynum = 1;
                        }
                    }
                    NameResolutionCollection ncCol = service.ResolveName(lnLegDN, ResolveNameSearchLocation.DirectoryOnly, true);
                    foreach (NameResolution nc in ncCol)
                    {
                        Console.WriteLine(nc.Mailbox.Address);
                        Console.WriteLine(nc.Contact.DisplayName);
                    }
                    Console.WriteLine(lnLegDN);
    
    Cheers
    Glen