Reading Outlook Mail with C#

后端 未结 1 888
半阙折子戏
半阙折子戏 2020-12-14 21:44

I am using the following code as I attempt to connect to my Outlook mail. Now, I must be doing something wrong because I try to get the inbox mails and I always get 0 mails

相关标签:
1条回答
  • 2020-12-14 22:20

    I could solve this! It was quite easy actually. Here is how I could access the desired folder:

    // my-account@myserver.com is the name of my account
    // Unsent mails is the name of the folder I wanted to access
    inboxFolder = nameSpace.Folders["my-account@myserver.com"].Folders["Unsent mails"];
    
    foreach (Microsoft.Office.Interop.Outlook.MailItem mailItem in inboxFolder.Items)
    {
        if (mailItem.UnRead) // I only process the mail if unread
        {
            Console.WriteLine("Accounts: {0}", mailItem.Body);
        }    
    }
    
    0 讨论(0)
提交回复
热议问题