views:

736

answers:

1

I am using C# to process a message in my Outlook inbox that contains attachments. One of the attachments is of type olEmbeddeditem. I need to be able to process the contents of that attachment. From what I can tell I need to save the attachment to disk and use CreateItemFromTemplate which would return an object.

The issue I have is that an olEmbeddeditem can be any of the Outlook object types MailItem, ContactItem, MeetingItem, etc. How do you know which object type a particular olEmbeddeditem attachment is going to be so that you know the object that will be returned by CreateItemFromTemplate?

Alternatively, if there is a better way to get olEmbeddeditem attachment contents into an object for processing I'd be open to that too.

+1  A: 

I found the following code on Google Groups for determining the type of an Outlook object:

Type t = SomeOutlookObject.GetType();
string messageClass = t.InvokeMember("MessageClass",
  BindingFlags.Public | 
  BindingFlags.GetField | 
  BindingFlags.GetProperty,
  null,
  SomeOutlookObject,
  new object[]{}).ToString();
Console.WriteLine("\tType: " + messageClass);

I don't know if that helps with an olEmbedded item, but it seems to identify regular messages, calendar items, etc.