VSTO Outlook从草稿发送MeetingItem

时间:2017-06-29 10:09:14

标签: c# outlook vsto outlook-addin

我正在处理我的插件并遇到下一个问题:看起来 MeetingItems 的工作方式不同,然后是MailItems。

我需要做什么:

  1. 在发送之前将MeetingItem保存到草稿中。
  2. 添加附件。
  3. 发送。
  4. 1要将MeetingItem保存到草稿:

    (Item as MeetingItem).GetAssociatedAppointment(false).GetInspector.Close(OlInspectorClose.olSave);
    

    有效。

    2。添加附件。

    Attaches = (Item as MeetingItem).GetAssociatedAppointment(false).Attachments;
    Attaches.Add(...).
    

    也可以。

    第3。发送邮件。

    Try1:

    (Item as MeetingItem).Send();  << it doesn't work.
    

    Try2:

    AppointmentItem appItem = Item.GetAssociatedAppointment(false);
    appItem.Send(); << It works. But MeetingItem is still in drafts folder (???)
    Item.Delete(); << Moved to deleted folder, and can't delete permanently.
    

    它认为第三步我做错了。你知道如何正确发送MeetingItem吗?

    更新

    当我发送MeetingItem时,Outlook会问我&#34;您是否要立即更新自己的日历&#34;。如果我按是,则根本不会调用Application_ItemSend回调,因此我无法添加附件。我很困惑那里发生了什么。

    Outlook message box

    更新2:

    看来,当我添加附件已经收到的消息时,我应该使用

    (Item as MailItem).Attachments.Add(...)
    

    但是当我发送邮件时,我应该使用

    (Item as MailItem).GetAssociatedAppointment(false).Attachments.Add(...)
    

    令人困惑。

2 个答案:

答案 0 :(得分:0)

会议项目不是为用户保存或操作而设计的 - 它们是在发送约会时自动创建的。您确实需要在约会中添加附件。如果您仍然只想在会议项目上使用它们,则可以处理Application.ItemSend事件并将附件添加到传递给事件处理程序的MeetingItem对象。

答案 1 :(得分:0)

无需使用MeetingItem类的GetAssociatedAppointment方法。您可以通过调用MeetingItem类的GetInspector属性直接获取Inspector类的实例。同样的规则适用于您需要调用的其他属性和方法 - SendAttachments等。

以编程方式创建会议请求时,首先要创建AppointmentItem对象而不是MeetingItem对象。要指示约会是会议,请将MeetingStatus对象的AppointmentItem属性设置为olMeeting。要发送会议请求,请将Send方法应用于该AppointmentItem对象。