VSTO Outlook:为主题行确定的邮件项创建动态自定义上下文菜单

时间:2010-07-28 17:31:42

标签: .net vsto ms-office outlook-addin outlook-2010

是否可以通过检查项目的内容将不同的项目添加到邮件项目自定义上下文菜单中?
例如,如果主题行包含“重要”,则仅添加项目。

1 个答案:

答案 0 :(得分:2)

这似乎有效。

void Application_ItemContextMenuDisplay(Office.CommandBar CommandBar, Outlook.Selection Selection)
    {
        foreach (Outlook.MailItem m in Selection)
        {
            if (m.Subject.Contains("IMPORTANT"))
            {
                DeliveryFailureButton(CommandBar, Selection);
                break;
            }
        }
    }

    void DeliveryFailureButton(Office.CommandBar CommandBar, Outlook.Selection Selection)
    {
        Office.CommandBarButton btn = CommandBar.Controls.Add(
              Office.MsoControlType.msoControlButton,
              missing, missing, missing, true) as
              Office.CommandBarButton;
        btn.Caption = "Move to IMPORTANT messages";

        btn.Click += (Office.CommandBarButton Ctrl, ref bool CancelDefault) =>
        {
            string msg = "CRM Records\r\n";

            foreach (Outlook.MailItem item in Selection)
            {
                if (item is Outlook.MailItem)
                {
                    var mitem = item as Outlook.MailItem;
                    msg += "\r\n" + MoveToImportant(mitem);
                }
            }

            MessageBox.Show(msg);

        };
    }