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

时间:2010-12-29 22:27:45

标签: c# winforms outlook

我正在尝试从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());
        }

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

感谢您提前协助。

1 个答案:

答案 0 :(得分: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());
        }

希望这有助于其他任何人:D