C# 在outlook上答复时获取上一个邮件项目

C# 在outlook上答复时获取上一个邮件项目,c#,interop,office-interop,outlook-addin,mailitem,C#,Interop,Office Interop,Outlook Addin,Mailitem,我们正在开发一个outlook插件。我们提供一个按钮作为默认发送按钮的替代。我们需要将按钮回复的所有邮件项目保存到特定类别。 当用户回复电子邮件(在new inspector中)时,我如何才能获得要回复的主邮件项目?您可以使用MailItem类的方法,该方法返回表示此项目所属对话的对象 如果项目不存在对话,GetConversation将返回Null(在Visual Basic中为Nothing)。在以下情况下,项目不存在对话: 该项目尚未保存。可以通过编程、用户操作或自动保存来保存项 对于可

我们正在开发一个outlook插件。我们提供一个按钮作为默认发送按钮的替代。我们需要将按钮回复的所有邮件项目保存到特定类别。 当用户回复电子邮件(在new inspector中)时,我如何才能获得要回复的主邮件项目?

您可以使用MailItem类的方法,该方法返回表示此项目所属对话的对象

如果项目不存在对话,GetConversation将返回Null(在Visual Basic中为Nothing)。在以下情况下,项目不存在对话:

  • 该项目尚未保存。可以通过编程、用户操作或自动保存来保存项
  • 对于可以发送的项目(例如,邮件项目、约会项目或联系人项目),该项目尚未发送
  • 已通过Windows注册表禁用对话
  • 商店不支持对话视图(例如,Outlook在传统联机模式下运行,而Microsoft Exchange Server 2010的版本早于Microsoft Exchange Server 2010)。使用存储对象的IsConversationEnabled属性确定存储是否支持对话视图
对话表示一个或多个文件夹和存储中的一个或多个项目。如果将对话中的项目移动到“已删除的项目”文件夹,然后使用GetChildren、GetRootItems或GetTable方法枚举对话,则返回的对象中将不包括该项目

void DemoConversation() 
{ 
   object selectedItem = 
    Application.ActiveExplorer().Selection[1]; 
   // This example uses only 
   // MailItem. Other item types such as 
   // MeetingItem and PostItem can participate 
   // in the conversation. 
   if (selectedItem is Outlook.MailItem) 
   { 
      // Cast selectedItem to MailItem. 
      Outlook.MailItem mailItem = 
       selectedItem as Outlook.MailItem; 
      // Determine the store of the mail item. 
      Outlook.Folder folder = mailItem.Parent 
       as Outlook.Folder; 
      Outlook.Store store = folder.Store; 
      if (store.IsConversationEnabled == true) 
      { 
        // Obtain a Conversation object. 
        Outlook.Conversation conv = 
         mailItem.GetConversation(); 
        // Check for null Conversation. 
        if (conv != null) 
        { 
          // Obtain Table that contains rows 
          // for each item in the conversation. 
          Outlook.Table table = conv.GetTable(); 
          Debug.WriteLine("Conversation Items Count: " + 
           table.GetRowCount().ToString()); 
          Debug.WriteLine("Conversation Items from Table:"); 
          while (!table.EndOfTable) 
          { 
            Outlook.Row nextRow = table.GetNextRow(); 
            Debug.WriteLine(nextRow["Subject"] 
             + " Modified: " 
             + nextRow["LastModificationTime"]); 
          } 
          Debug.WriteLine("Conversation Items from Root:"); 
          // Obtain root items and enumerate the conversation. 
          Outlook.SimpleItems simpleItems 
           = conv.GetRootItems(); 
          foreach (object item in simpleItems) 
          { 
             // In this example, only enumerate MailItem type. 
             // Other types such as PostItem or MeetingItem 
             // can appear in the conversation. 
             if (item is Outlook.MailItem) 
             { 
                Outlook.MailItem mail = item 
                  as Outlook.MailItem; 
                Outlook.Folder inFolder = 
                mail.Parent as Outlook.Folder; 
                string msg = mail.Subject 
                  + " in folder " + inFolder.Name; 
                Debug.WriteLine(msg); 
             } 
             // Call EnumerateConversation 
             // to access child nodes of root items. 
             EnumerateConversation(item, conv); 
          } 
        } 
      } 
    } 
  } 


  void EnumerateConversation(object item, 
   Outlook.Conversation conversation) 
  { 
     Outlook.SimpleItems items = 
      conversation.GetChildren(item); 
     if (items.Count > 0) 
     { 
        foreach (object myItem in items) 
        { 
           // In this example, only enumerate MailItem type. 
           // Other types such as PostItem or MeetingItem 
           // can appear in the conversation. 
           if (myItem is Outlook.MailItem) 
           { 
              Outlook.MailItem mailItem = 
                myItem as Outlook.MailItem; 
              Outlook.Folder inFolder = 
                mailItem.Parent as Outlook.Folder; 
              string msg = mailItem.Subject 
                + " in folder " + inFolder.Name; 
              Debug.WriteLine(msg); 
            } 
            // Continue recursion. 
            EnumerateConversation(myItem, conversation); 
          } 
       } 
    } 
您可以使用MailItem类的方法,该类返回一个对象,该对象表示此项所属的会话

如果项目不存在对话,GetConversation将返回Null(在Visual Basic中为Nothing)。在以下情况下,项目不存在对话:

  • 该项目尚未保存。可以通过编程、用户操作或自动保存来保存项
  • 对于可以发送的项目(例如,邮件项目、约会项目或联系人项目),该项目尚未发送
  • 已通过Windows注册表禁用对话
  • 商店不支持对话视图(例如,Outlook在传统联机模式下运行,而Microsoft Exchange Server 2010的版本早于Microsoft Exchange Server 2010)。使用存储对象的IsConversationEnabled属性确定存储是否支持对话视图
对话表示一个或多个文件夹和存储中的一个或多个项目。如果将对话中的项目移动到“已删除的项目”文件夹,然后使用GetChildren、GetRootItems或GetTable方法枚举对话,则返回的对象中将不包括该项目

void DemoConversation() 
{ 
   object selectedItem = 
    Application.ActiveExplorer().Selection[1]; 
   // This example uses only 
   // MailItem. Other item types such as 
   // MeetingItem and PostItem can participate 
   // in the conversation. 
   if (selectedItem is Outlook.MailItem) 
   { 
      // Cast selectedItem to MailItem. 
      Outlook.MailItem mailItem = 
       selectedItem as Outlook.MailItem; 
      // Determine the store of the mail item. 
      Outlook.Folder folder = mailItem.Parent 
       as Outlook.Folder; 
      Outlook.Store store = folder.Store; 
      if (store.IsConversationEnabled == true) 
      { 
        // Obtain a Conversation object. 
        Outlook.Conversation conv = 
         mailItem.GetConversation(); 
        // Check for null Conversation. 
        if (conv != null) 
        { 
          // Obtain Table that contains rows 
          // for each item in the conversation. 
          Outlook.Table table = conv.GetTable(); 
          Debug.WriteLine("Conversation Items Count: " + 
           table.GetRowCount().ToString()); 
          Debug.WriteLine("Conversation Items from Table:"); 
          while (!table.EndOfTable) 
          { 
            Outlook.Row nextRow = table.GetNextRow(); 
            Debug.WriteLine(nextRow["Subject"] 
             + " Modified: " 
             + nextRow["LastModificationTime"]); 
          } 
          Debug.WriteLine("Conversation Items from Root:"); 
          // Obtain root items and enumerate the conversation. 
          Outlook.SimpleItems simpleItems 
           = conv.GetRootItems(); 
          foreach (object item in simpleItems) 
          { 
             // In this example, only enumerate MailItem type. 
             // Other types such as PostItem or MeetingItem 
             // can appear in the conversation. 
             if (item is Outlook.MailItem) 
             { 
                Outlook.MailItem mail = item 
                  as Outlook.MailItem; 
                Outlook.Folder inFolder = 
                mail.Parent as Outlook.Folder; 
                string msg = mail.Subject 
                  + " in folder " + inFolder.Name; 
                Debug.WriteLine(msg); 
             } 
             // Call EnumerateConversation 
             // to access child nodes of root items. 
             EnumerateConversation(item, conv); 
          } 
        } 
      } 
    } 
  } 


  void EnumerateConversation(object item, 
   Outlook.Conversation conversation) 
  { 
     Outlook.SimpleItems items = 
      conversation.GetChildren(item); 
     if (items.Count > 0) 
     { 
        foreach (object myItem in items) 
        { 
           // In this example, only enumerate MailItem type. 
           // Other types such as PostItem or MeetingItem 
           // can appear in the conversation. 
           if (myItem is Outlook.MailItem) 
           { 
              Outlook.MailItem mailItem = 
                myItem as Outlook.MailItem; 
              Outlook.Folder inFolder = 
                mailItem.Parent as Outlook.Folder; 
              string msg = mailItem.Subject 
                + " in folder " + inFolder.Name; 
              Debug.WriteLine(msg); 
            } 
            // Continue recursion. 
            EnumerateConversation(myItem, conversation); 
          } 
       } 
    } 

用户可以从资源管理器或检查器中进行答复

对于Explorer,捕获
Explorer.SelectionChange
事件并在所选项目上设置事件接收器。您可以捕获
MailItem.Reply/ReplyAll/Forward
事件


对于检查器,捕获
Application.inspectors.NewInspector
事件,并在从
Inspector.CurrentItem
属性返回的
MailItem
上设置事件接收器。然后,您将再次捕获
MailItem.Reply/ReplyAll/Forward
事件。

用户可以从资源管理器或检查器中进行回复

对于Explorer,捕获
Explorer.SelectionChange
事件并在所选项目上设置事件接收器。您可以捕获
MailItem.Reply/ReplyAll/Forward
事件


对于检查器,捕获
Application.inspectors.NewInspector
事件,并在从
Inspector.CurrentItem
属性返回的
MailItem
上设置事件接收器。然后,您将再次捕获
MailItem.Reply/replyll/Forward
事件。

这里有很多知识,但对我的问题来说似乎很复杂。这里有很多知识,但对我的问题来说似乎很复杂。@DmitryStreblechenko您所说的所选项目上的事件接收器是什么意思!现在,由于其他原因,我同时捕获了(Reply/replyll/Forward事件)和newinspector事件,但是如何从newinspector事件获取原始邮件项目的内容呢。我在新Ispector中收到的邮件项目我在其中放置内容,我在新检查器事件中无法获取以前的内容如果您正在捕获回复/回复/转发事件,您已经知道引发这些事件的电子邮件,对吗?@DmitryStreblechenko您所选项目上的事件接收器是什么意思!现在,由于其他原因,我同时捕获了(Reply/replyll/Forward事件)和newinspector事件,但是如何从newinspector事件获取原始邮件项目的内容呢。我在新的Ispector中收到的邮件项目我在新的Inspector Event中收到以前的内容有问题如果你在捕获回复/回复/转发事件,你已经知道引发这些事件的电子邮件了,对吗?