共享邮箱上的MailItem.GetConversation()

时间:2019-06-25 09:22:56

标签: outlook vsto outlook-addin office-interop

我正在使用以下代码来显示会话中原始电子邮件的属性。

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

它在我的个人收件箱和添加为其他收件箱的共享邮箱上都可以正常工作。

但是我拥有完全访问权限但在Outlook客户端中具有自动映射功能的所有其他共享邮箱都无法正常工作。

有人知道mailItem.GetConversation()是否可以与未添加为其他帐户但自动映射的共享邮箱一起使用吗?

由于在这些共享邮箱上,即使同一对话中还有其他电子邮件,我也会收到Conversation Items Count: 0

谢谢。

1 个答案:

答案 0 :(得分:0)

  

它在我的个人收件箱和添加为其他收件箱的共享邮箱上都可以正常工作。

似乎您只是在个人资料中添加了第二个帐户,而不是共享邮箱。

如果该项目不存在对话,则

GetConversation返回Null(在Visual Basic中为Nothing)。如果商店不支持“对话”视图,则该项目不存在对话(例如,对于Microsoft Exchange Server 2010之前的Microsoft Exchange版本,Outlook以经典的在线模式运行)。

使用Store对象的IsConversationEnabled属性来确定商店是否支持Conversation viewGetConversation应该起作用。