找出用户右键单击的联系人

时间:2018-03-07 18:48:19

标签: c# vsto contextmenu outlook-addin outlook-2013

提前感谢您的帮助。我一直在寻找解决方案。

上下文:当用户右键单击某个联系人时,我添加了一个新的上下文菜单。其ID为ContextMenuContactCardRecipient

问题:当用户在此上下文菜单中并单击我的新按钮时,我需要知道用户右键单击哪个联系人才能进入上下文菜单。

我找不到检索联系人项目详情的方法......有没有人知道我该如何做到这一点?

这里提供的答案对我不起作用: How can I reliably get the object of a contact context menu in an Outlook 2013 addin?

谢谢!

1 个答案:

答案 0 :(得分:1)

也许为时已晚,但可能对其他人有帮助!

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;
    }