C# Winforms: Accessing Outlook with Multiple Mailboxes
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.
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
精彩评论