Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cannot get Outlook mailitems
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Cannot get Outlook mailitems
Miscellaneous
Thread ID:
00858420
Message ID:
00858420
Views:
53
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
Map
View

Click here to load this message in the networking platform