简体   繁体   English

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

[英]C# Winforms: Accessing Outlook with Multiple Mailboxes

I'm trying to access an Outlook Mailbox from C# / Winforms. 我正在尝试从C#/ Winforms访问Outlook邮箱。 I have two separate mailboxes that my user profile can access. 我有两个单独的邮箱,我的用户配置文件可以访问。 How can i code it so that it only pulls from a certain mailbox? 我如何编码它,以便它只从某个邮箱拉?

Here's what I have currently, but it only pulls the info from my default account mailbox. 这是我目前所拥有的,但它只从我的默认帐户邮箱中提取信息。

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

I also need to tell it certain folders along with the inbox (like above). 我还需要告诉它某些文件夹以及收件箱(如上所述)。

Thanks for the assistance in advance. 感谢您的帮助。

I finally figured out how to designate which mailbox I wanted to open. 我终于想出了如何指定我想打开的邮箱。 I'll post it here for others to use in the future. 我会在这里发布,供其他人在将来使用。

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

Hope this helps anyone else :D 希望这可以帮助其他人:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM