none
Receive from/to/cc/bcc addresses from emails down in the same conversation/thread? RRS feed

  • Question

  • Hi,

    I would like to get a list of each email in the from/to/cc/bcc fields of previous emails in the email chain (assuming users have pressed reply/reply all without removing the thread history down in the email).

    Do you know this can best be done? Do I have to parse information such as the one below to get all email addresses or is there a better way? Maybe the information below is not standardized either, I am not sure.

    From: Name <myemail@myemail.com>
    Date: 2016-05-16 20:58 GMT+02:00
    Subject: RE: subject
    To: "Recipient name" <recipientemail@domain.com>

    Tuesday, May 17, 2016 4:10 PM

Answers

  • Hello,

    You can use the GetConversation method of the MailItem class which obtains a Conversation object that represents the conversation to which this item belongs.

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

    A conversation represents one or more items in one or more folders and stores. If you move an item in a conversation to the Deleted Items folder and subsequently enumerate the conversation by using the GetChildren, GetRootItems, or GetTable method, the item will not be included in the returned object.


    [custom.development]

    Tuesday, May 17, 2016 4:29 PM
  • Yes, typically you will see the original email in the message body. 

    Also you may try to use low-level property explorers such as MFCMAPI or OutlookSpy for viewing hidden MAPI properties. 


    [custom.development]


    Tuesday, May 17, 2016 8:14 PM

All replies

  • Hello,

    You can use the GetConversation method of the MailItem class which obtains a Conversation object that represents the conversation to which this item belongs.

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

    A conversation represents one or more items in one or more folders and stores. If you move an item in a conversation to the Deleted Items folder and subsequently enumerate the conversation by using the GetChildren, GetRootItems, or GetTable method, the item will not be included in the returned object.


    [custom.development]

    Tuesday, May 17, 2016 4:29 PM
  • This seems overly complex plus I am not sure if it works when Outlook is having an email threads with another client. Also, not sure what would happen if an older email is deleted from the Outlook mailbox, while the email is still down in the email thread. The method of parsing the email content would work then.

    When I click reply I get the original message included below right? I mean, it is just not the email client that looks like it is there below I assume? 

    Tuesday, May 17, 2016 4:44 PM
  • Yes, typically you will see the original email in the message body. 

    Also you may try to use low-level property explorers such as MFCMAPI or OutlookSpy for viewing hidden MAPI properties. 


    [custom.development]


    Tuesday, May 17, 2016 8:14 PM