Outlook 任务请求接受事件

Outlook task request accepted event

我正在为 Outlook 开发一个插件,对此我还很陌生。

我需要知道我的任务请求何时被接受,但我找不到这样的事件。

我尝试订阅任务的 PropertyChange 事件并检查 ResponseState 是否为 olTask​​Accept,但这不起作用,可能是因为此 属性 更改的任务对象与正在侦听事件的任务对象不同。

我看到有一个 TaskRequestAcceptItem 对象,但是 msdn 没有说如何获取它,只是说你不能创建它。

所以我的问题是如何订阅在我发送的任务请求被接受时触发的事件,或者至少我如何才能获得它被接受的日期时间?

我正在使用 VS 2013 和 Outlook 2010

void buttonGroup1_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            _task = Application.CreateItem(Outlook.OlItemType.olTaskItem);
            Outlook.MailItem email = _selection[1] as Outlook.MailItem;

            _task.Subject = email.Subject;
            _task.Body = email.Body;
            _task.ReminderSet = true;
            _task.ReminderTime = new DateTime(2015, 03, 12, 15, 41, 0);
            _task.PropertyChange += task_PropertyChange;
            _task.Recipients.Add("x@x.com");
            _task.Assign();
            (_task as Outlook._TaskItem).Send();
        }

        Dictionary<Outlook.TaskItem, DateTime> taskAccepts = new Dictionary<Outlook.TaskItem, DateTime>();

        void task_PropertyChange(string Name)
        {
            if (Name == "ResponseState" && _task.ResponseState == Outlook.OlTaskResponse.olTaskAccept)
            {
                taskAccepts.Add(_task, DateTime.Now); // this never executes
            }
        }

如果委派用户接受任务,ResponseState 属性 设置为 olTask​​Accept。至少尝试保存新创建的项目以触发 PropertyChange 事件。

void buttonGroup1_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)

命令栏已弃用,不再在 Outlook 中使用。您需要改用 Fluent UI。

如果其他人遇到这个问题,我就是这样做的。我监听何时将 TaskRequestAcceptItem 添加到收件箱:

    Outlook.Items _items;
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Outlook.Folder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;

        _items = inbox.Items;
        _items.ItemAdd += items_ItemAdd;
    }

    private void items_ItemAdd(object Item)
    {
        if (Item is Outlook.TaskRequestAcceptItem)
        {
            Outlook.TaskItem task = (Item as Outlook.TaskRequestItem).GetAssociatedTask(false);
            // some code here
        }
    }

还有另一种方法,如果代码在接收方的机器上运行,您可以监听 TaskRequestItem,然后监听关联任务的 PropertyChange 事件

    Outlook.TaskItem _task;
    private void items_ItemAdd(object Item)
    {
        if (Item is Outlook.TaskRequestItem)
        {
            _task = (Item as Outlook.TaskRequestItem).GetAssociatedTask(false);
            _task.PropertyChange += item_PropertyChange;
        }
    }

    void item_PropertyChange(string Name)
    {
        if (Name == "ResponseState" && _task.ResponseState == Outlook.OlTaskResponse.olTaskAccept)
        {
            //some code here
        }
    }