tags:

views:

39

answers:

1

I'm trying to use the following to retrieve a MailItem from Outlook via entryID and storeID. What do I do when the entryID/storeID aren't valid? I get a strange COMException saying that the action failed or that there's been a networking problem with Exchange or that it's not running. When I test for valid entryIDs/storeIDs it seems to work swell.

Outlook.Application app = new Outlook.Application;
Outlook.Namespace ns = app.GetNamepace("MAPI");
Outlook.MailItem mailItem = ns.GetItemFromId("myMailItemEntryId","myMailItemParentStoreID");
A: 

Hm. Could it be as simple as:

Outlook.MailItem mailItem = null;

try {
  Outlook.MailItem mailItem = ns.GetItemFromId("myMailItemEntryId","myMailItemParentStoreID");
} catch (Exception x) {
  // do something useful handle the error
}

?

Tomalak
I get a strange COMException after it's tried to retrieve the MailItem and after that something happens to the GUI handling of my application, for example controls aren't moved from a TabPage to the newly selected one and so on. I don't know what causes this, but it works when the exception doesn't occur.
Zolomon
I wonder if it's possible to check if the mail/folder exists in outlook before trying to retrieve it?
Zolomon