C#Winforms:使用多个邮箱访问Outlook

Ale*_*lex 3 c# outlook winforms

我正在尝试从C#/ Winforms访问Outlook邮箱.我有两个单独的邮箱,我的用户配置文件可以访问.我如何编码它,以便它只从某个邮箱拉?

这是我目前所拥有的,但它只从我的默认帐户邮箱中提取信息.

 try
        {
            OutLook.Application oApp = new OutLook.Application();
            OutLook.NameSpace oNS = (OutLook.NameSpace)oApp.GetNamespace("MAPI");
            oNS.Logon(Missing.Value, Missing.Value, false, true);
            OutLook.MAPIFolder theInbox = oNS.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox);
            int count = theInbox.UnReadItemCount;
            inboxLabel.Text = inboxLabel.Text + " " + count.ToString();
        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }
Run Code Online (Sandbox Code Playgroud)

我还需要告诉它某些文件夹以及收件箱(如上所述).

感谢您的帮助.

Ale*_*lex 10

我终于想出了如何指定我想打开的邮箱.我会在这里发布,供其他人在将来使用.

        try
        {
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");
            oNS.Logon(Missing.Value, Missing.Value, false, true);
            Outlook.MAPIFolder theInbox = oNS.Folders["Mailbox - Name Here"].Folders["Inbox"];

            ....Do you want with that Folder here....
        }
        catch (Exception e)
        {
            MessageBox.Show(e.ToString());
        }
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助其他人:D