General information
Title:
Cannot get Outlook mailitems
I trying to read my e-mail messages via Outlook but I cannot get it to work. I using VS2003 and PIAs (not VSOT). Any help??
Here is the code:
ol = new Outlook.Application();
ns = ol.GetNamespace("MAPI");
outbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
But if I try to get the mailitems via:
foreach (Outlook.MailItem it in inbox.Items)
{
MessageBox.Show(it.Subject);
}
or
Outlook.Items items = inbox.Items;
for (int i = 1; i < items.Count; i++)
{
Outlook.MailItem item = (Outlook.MailItem)items[i];
}
I get a unhandled exception of type 'System.InvalidCastException'
What am I doing wrong?
John
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only