2017-03-16 11 views
0

Outlookアドイン(c#+ vsto)からOutlookの会話クリーンアップを呼び出す必要があります。 私はオフィスのリボンバーに自分のボタンを持っていて、それをクリックすると、現在選択されているメールアイテムでOutlookの会話のクリーンアップを呼び出す必要があります。 これは可能なのですか?Outlookアドインから会話クリーンアップを呼び出す

答えて

0

Outlookアイテムは、このアイテムが属する会話を表すConversationオブジェクトを取得するGetConversationメソッドを提供します。

GetConversationは、アイテムの会話が存在しない場合はNull(Visual BasicではNothing)を返します。次のシナリオでアイテムの会話が存在しません。

•アイテムが保存されていません。アイテムは、プログラムで、ユーザーの操作によって、または自動保存によって保存することができます。

•送信可能なアイテム(メールアイテム、予定アイテム、連絡先アイテムなど)の場合、そのアイテムは送信されていません。

•会話はWindowsレジストリで無効になっています。

•Microsoft Exchange Server 2010より前のバージョンのMicrosoft Exchangeに対してOutlookが従来のオンラインモードで実行されているなど、ストアは会話形式のビューをサポートしていません。 StoreオブジェクトのIsConversationEnabledプロパティを使用して、ストアが会話ビューをサポートしているかどうかを判断します。

次のコード例では、エクスプローラウィンドウで選択したアイテムがメールアイテムであることを前提としています。コード例は、選択したメールアイテムが関連付けられている会話を取得し、その会話の各アイテムを列挙し、アイテムの件名を表示します。 DemoConversationメソッドは、選択したメールアイテムのGetConversationメソッドを呼び出して、関連する会話オブジェクトを取得します。 DemoConversationはConversationオブジェクトのGetTableGetRootItemsメソッドを呼び出して、TableオブジェクトとSimpleItemsコレクションをそれぞれ取得します。

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); 
      } 
     } 
     } 
+0

ユージーン、私の質問にお返事ありがとうございます。上記のアプローチを使用するためには、各メッセージ本文を、表にある他のすべてのメッセージの本文と比較する必要があります。それ以外は、Outlookにはさまざまなケースの本文があります(メッセージ本文には 'mailto:'があり、電子メールアドレスは[<]で囲まれていますが、 '<'は別の場所で使用されています。時間フィールド)。したがって、ホイールの再作成ではなく、Outlookの組み込みの対話クリーンアップ機能を呼び出す方が良いかもしれません。 –

関連する問題