C # Winforms: Access Outlook with Multiple Mailboxes

I am trying to access an Outlook mailbox from C # / Winforms. I have two separate mailboxes that my user profile can access. How can I encode it so that it retrieves only from a specific mailbox?

Here is what I have, but it only extracts information from the 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 specify specific folders along with mailboxes (e.g. above).

Thanks for the help in advance.

+3
source share
1 answer

- , , . , .

        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

+9

Source: https://habr.com/ru/post/1782685/


All Articles