none
How to retrieve CustomAttribute/Extended Properties of a Exchange user who is logged in Outlook RRS feed

  • Question

  • I am trying to fetch extended properties for a exchange user who is logged in Outlook.

    Here is my code snippet,but the extended-properties collection has no results.

    private string fetchDetailsFromAD()
            {
                //get currently logged in user in OUTLOOK
                string email_from=null;
                Outlook.AddressEntry currentUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
                foreach (Microsoft.Office.Interop.Outlook.Account acct in Globals.ThisAddIn.Application.Session.Accounts)
                {
                    if (acct.CurrentUser.Address == currentUser.Address)
                    {
                        email_from = acct.SmtpAddress;
                        break;
                    }
                }
                service.Credentials = new NetworkCredential("han@zepto.com.my", "abcd1234!");
    
                // Look up the user's EWS endpoint by using Autodiscover.
                service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
                
                Contact contact = null;
                try
                {
                    NameResolutionCollection allContacts = service.ResolveName(email_from, ResolveNameSearchLocation.DirectoryOnly, true);
    
                    if (allContacts.Any())
                    {
                        contact = allContacts[0].Contact;
                    }
                           }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error in GetContactInfo(): "+ ex.Message);
                    //throw;
                    return "";
                }
                
                
                return contact.JobTitle;
            }

    So I have Contact object which has ExtendedProperties,but it is an empty collection.

    Please let me know how could I fetch them.

    For this user I have set CustomAttrribute10 as per attached image.


    Point5Nyble

    Thursday, November 19, 2015 7:39 AM

Answers

  • Those properties aren't available in EWS you would need to use either LDAP to access Active Directory directly or it looks like your coding a VSTO Outlook Plug which don't you just use the OOM and fetch the  PR_EMS_AB_EXTENSION_ATTRIBUTE_1  property

        Outlook.Recipient rcp = ParentFolder.Application.Session.CreateRecipient(Name);
        rcp.Resolve();                                    
        rcp.AddressEntry.GetExchangeUser().PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x802D001E");

    Cheers
    Glen


    • Edited by Glen ScalesMVP Friday, November 20, 2015 3:28 AM
    • Marked as answer by Point5Nyble Friday, November 20, 2015 6:36 AM
    Friday, November 20, 2015 3:27 AM

All replies

  • Those properties aren't available in EWS you would need to use either LDAP to access Active Directory directly or it looks like your coding a VSTO Outlook Plug which don't you just use the OOM and fetch the  PR_EMS_AB_EXTENSION_ATTRIBUTE_1  property

        Outlook.Recipient rcp = ParentFolder.Application.Session.CreateRecipient(Name);
        rcp.Resolve();                                    
        rcp.AddressEntry.GetExchangeUser().PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x802D001E");

    Cheers
    Glen


    • Edited by Glen ScalesMVP Friday, November 20, 2015 3:28 AM
    • Marked as answer by Point5Nyble Friday, November 20, 2015 6:36 AM
    Friday, November 20, 2015 3:27 AM
  • Thanks Glen,I have been directed in right direction and I am now able to fetch the extended properties as suggested.

    Here is the code snippet.

    private string fetchDetailsFromAD() { var myprop=""; try { Outlook.AddressEntry currentUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry; if (currentUser.Type == "EX") { myprop = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry.GetExchangeUser().PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x8036001E"); //MessageBox.Show(myprop); } } catch

    {

    throw;

    }

    return myprop;

    }

    Thanks a lot


    Cheers

    Point5Nyble


    • Edited by Point5Nyble Friday, November 20, 2015 6:25 AM Code update
    Friday, November 20, 2015 6:24 AM