Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未使用Interop Outlook检索文件夹中的所有邮件项_C#_Office Interop_Outlook 2016 - Fatal编程技术网

C# 未使用Interop Outlook检索文件夹中的所有邮件项

C# 未使用Interop Outlook检索文件夹中的所有邮件项,c#,office-interop,outlook-2016,C#,Office Interop,Outlook 2016,不知道为什么,但我没有从文件夹中检索所有邮件 代码似乎只检索outlook中的邮件,但当我单击“单击此处查看Microsoft Exchange上的详细信息”时,outlook中的这些文件夹中会有更多邮件。是那些没有被找回的 那么,如何检索文件夹中的所有邮件呢 我的代码看起来像这样 static void ProcessMessages(Outlook.Folder folder) { // Iterate through all items ("mes

不知道为什么,但我没有从文件夹中检索所有邮件

代码似乎只检索outlook中的邮件,但当我单击“单击此处查看Microsoft Exchange上的详细信息”时,outlook中的这些文件夹中会有更多邮件。是那些没有被找回的

那么,如何检索文件夹中的所有邮件呢

我的代码看起来像这样

    static void ProcessMessages(Outlook.Folder folder)
    {
        // Iterate through all items ("messages") in a folder
        Outlook.Items ItemsInFolder = folder.Items;

        // Number of messages in the folder
        Console.WriteLine("count " + ItemsInFolder.Count);

        // If ItemsInFolder is not null then lets process through those messages.
        if (ItemsInFolder != null)
        {
            try
            {
                foreach (Outlook.MailItem mailitem in ItemsInFolder)
                {
                    string senderAddress = mailitem.Sender.Address;
                    Console.WriteLine("senderAddress " + senderAddress);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occurred: '{0}'", e);
            }
        }
    }
计数为ItemsInFolder仅显示Outlook文件夹中的项目数,而不是存储在Exchange上的文件夹中的实际项目数

那么,获取文件夹中的所有电子邮件(包括outlook缓存中的邮件和exchange上的邮件)的最佳方法是什么

我曾尝试使用Interop Outlook库,并尝试创建一个C#VSTO addin项目,得到了相同的结果


有什么想法吗?

有人吗??谁能给我指一下正确的方向吗。我需要循环浏览文件夹中的所有邮件。outlook中的邮件以及未缓存在outlook中但仍在Exchange文件夹中的邮件。