【问题标题】:How to track mail correspondances如何跟踪电子邮件通信
【发布时间】:2015-04-18 20:54:30
【问题描述】:

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

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

我尝试将 MailItem.UserProperty 添加到 E-mail 对象,但显然它没有发送。

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

【问题讨论】:

标签: vba outlook


【解决方案1】:

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

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

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

您可以使用 MailItem 类的 GetConversation 方法来获取一个 Conversation 对象,该对象表示该项目所属的对话。请注意,如果项目不存在对话,GetConversation 将返回 Null(在 Visual Basic 中为 Nothing)。在以下情况下不存在与项目的对话:

  • 该项目尚未保存。可以通过编程方式、用户操作或自动保存来保存项目。
  • 对于可以发送的项目(例如,邮件项目、约会项目或联系人项目),该项目尚未发送。
  • 已通过 Windows 注册表禁用对话。
  • 应用商店不支持对话视图(例如,Outlook 在经典联机模式下针对早于 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); 
        } 
     } 
  } 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2018-09-19
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    相关资源
    最近更新 更多