0

I am using following code to display properties from original email in conversation.

void DemoConversation()
{
    object selectedItem = 
        Application.ActiveExplorer().Selection[1];
    // For this example, you will work only with 
    //MailItem. Other item types such as
    //MeetingItem and PostItem can participate 
    //in Conversation.
    if (selectedItem is Outlook.MailItem)
    {
        // Cast selectedItem to MailItem.
        Outlook.MailItem mailItem =
            selectedItem as Outlook.MailItem; ;
        // Determine store of mailItem.
        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 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 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 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 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);
        }
    }
}

It works fine on my personal inbox and shared mailbox added as additional inbox.

But all other shared mailboxes which I have full access but have auto-mapped in my Outlook client doesn't work.

Does anyone know if mailItem.GetConversation() supposed to work with shared mailboxes which are not added as additional account but are auto-mapped?

Because on these shared mailboxes, I get Conversation Items Count: 0even if there are other emails in the same conversation.

Thank you.

Bubuhubu
  • 81
  • 9

2 Answers2

0

It works fine on my personal inbox and shared mailbox added as additional inbox.

It seems you just added a second account to the profile, not a shared mailbox.

GetConversation returns Null (Nothing in Visual Basic) if no conversation exists for the item. No conversation exists for an item if the store does not support Conversation view (for example, Outlook is running in classic online mode against a version of Microsoft Exchange earlier than Microsoft Exchange Server 2010).

Use the IsConversationEnabled property of the Store object to determine whether the store supports Conversation view and GetConversation is supposed to work.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi @Eugene thanks for the reply. `IsConversationEnabled` returns true. Also `Outlook.Conversation conv = mailItem.GetConversation();` works fine since code returns true for `if (conv != null) { }` . It seems like code doesn't work when it comes to `Outlook.SimpleItems simpleItems = conv.GetRootItems();` because `simpleItems.Count` returns 0. So the problem is `conv.GetRootItems()` returns value for my person inbox but returns 0 on shared mailbox. – Bubuhubu Jun 25 '19 at 15:32
  • It seems you need to add another account to be able to work with conversations in the store. – Eugene Astafiev Jun 25 '19 at 15:36
  • So you are saying that there is no way to make conversation working on shared mailbox? Only way is to add it as another account? Thanks. – Bubuhubu Jun 25 '19 at 15:38
  • If it doesn't work for you, there are no tools to help. – Eugene Astafiev Jun 25 '19 at 15:55
0

Indeed, GetRootItems() return 0 for shared mailbox which is frustrating because Outlooks shows the mails as Conversations. What I have noticed is, that each email in Inbox of that shared mailbox has ConversationID assigned correctly, so solution is to iterated the folder and build own conversation collection based on ConversationID value. It contains not only incoming messages but also sent items, so really all elements of conversations. It works as charm at least for my purpose which was to calculate response time for that shared mailbox and average length of conversations.

Marcin
  • 1