1

thank you in advance for your help. I have been looking for a solution by myself for a while.

The context: I added a new context menu when the user right-clicks on a contact. Its id is ContextMenuContactCardRecipient.

The problem: When the user is in this context menu and clicks on my new button, I need to know which contact the user right-clicked to get to the context menu.

I could not find a way to retrieve the contact items details... Does anyone have an idea on how I can do this?

The answer provided here does not work for me: How can I reliably get the object of a contact context menu in an Outlook 2013 addin?

Thank you!

Jeand
  • 11
  • 2

1 Answers1

0

Maybe too late but can be helpful for others!

XML

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <contextMenus>
        <contextMenu idMso="ContextMenuContactCardRecipient">
          <button id="myMenuBtn"
              label="get mail email"
              onAction="lookForMe"
              visible="true"/>
        </contextMenu>
      </contextMenus>
    </customUI>

C#

        public void lookForMe(IRibbonControl control)
    {
        Office.IMsoContactCard card = control.Context as Office.IMsoContactCard;
        string email = GetSmtpAddress(card);
        if (email != null)
        {
            System.Diagnostics.Process.Start("https://org.ad.com/" + email);
        }
    }

    private string GetSmtpAddress(Office.IMsoContactCard card)
    {
        if (card.AddressType == Office.MsoContactCardAddressType.msoContactCardAddressTypeOutlook)
        {
            Microsoft.Office.Interop.Outlook.Application host = Globals.ThisAddIn.Application;
            Microsoft.Office.Interop.Outlook.AddressEntry ae = host.Session.GetAddressEntryFromID(card.Address);

            if ((ae.AddressEntryUserType == Microsoft.Office.Interop.Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry 
                || ae.AddressEntryUserType == Microsoft.Office.Interop.Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry))
            {
                Microsoft.Office.Interop.Outlook.ExchangeUser ex = ae.GetExchangeUser();
                return ex.PrimarySmtpAddress;
            }
            else
                throw new System.Exception("unvalid address entry not found.");
        }
        else
            return card.Address;
    }
KhaledZero
  • 42
  • 9