3

I'm trying to access an Outlook Mailbox from C# / Winforms. 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.

Alex
  • 2,114
  • 9
  • 25
  • 34

1 Answers1

12

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

CragMonkey
  • 808
  • 1
  • 11
  • 22
Alex
  • 2,114
  • 9
  • 25
  • 34