如何跟踪邮件往来

How to track mail correspondances

有谁知道是否可以查明收件箱中的电子邮件是否是对我之前发送的邮件的回复?

示例:我向 A 发送了一封电子邮件,提出了一个问题。当 A 回复时,我想 link 我的原始邮件给他的回复。我的目标是将整个邮件通信保存在自定义文件夹中。

我已经尝试将 MailItem.UserProperty 添加到电子邮件对象,但显然它没有被发送。

我考虑过的另一种解决方案是在邮件正文中添加一个隐藏文本,以便在收到回复时搜索(假设我的原始邮件将包含在回复中)。

MailItem class 提供以下用于跟踪对话的属性:

  • ConversationID - 唯一标识 MailItem 对象所属的 Conversation 对象的字符串。
  • ConversationTopic - 表示 Outlook 项目对话主题的字符串。它是邮件的规范化主题,没有前缀字符串的主题。
  • ConversationIndex - 一个字符串,指示项目在对话线程中的相对位置。

如您所见,对话分组取决于主题行。

您可以使用代表该项目所属对话的 GetConversation method of the MailItem class to get a Conversation 对象。请注意,如果项目不存在对话,则 GetConversation returns Null(在 Visual Basic 中为 Nothing)。在以下情况下,项目不存在对话:

  • 该项目尚未保存。项目可以通过编程方式、用户操作或自动保存来保存。
  • 对于可以发送的项目(例如,邮件项目、约会项目或联系人项目),该项目尚未发送。
  • 已通过 Windows 注册表禁用对话。
  • 该商店不支持对话视图(例如,Outlook 在 classic 联机模式下针对早于 Microsoft Exchange Server 2010 的 Microsoft Exchange 版本运行。使用 Store 对象的 IsConversationEnabled 属性 来确定商店是否支持对话视图。

例如:

 public 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, enumerate only 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, enumerate only 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); 
        } 
     } 
  }