Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cannot get Outlook mailitems
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Cannot get Outlook mailitems
Divers
Thread ID:
00858420
Message ID:
00858420
Vues:
54
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
Répondre
Fil
Voir

Click here to load this message in the networking platform