0
votes

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.

2

2 Answers

1
votes

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.

0
votes

Working with email attachments that are also emails which in turn contains user defined properties that I want to access, then I perform the following steps:

Outlook.Application mailApplication = new Outlook.Application();
Outlook.NameSpace mailNameSpace = mailApplication.GetNamespace(“mapi”);
// make sure it is an embedded item
If(myAttachment.Type == Outlook.OlAttachmentType.olEmbeddeditem)
{
    myAttachment.Type.SaveAsFile(“temp.msg”);
    Outlook.MailItem attachedEmail = (Outlook.MailItem)mailNameSpace.OpenSharedItem(“temp.msg”);
    String customProperty = attachedEmail.PropertyAccessor.GetProperty(
        “http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-c000-000000000046}/myProp
}

If you open the MailItem using, then I will not have access to the properties as mentioned above:

Outlook.MailItem attachedEmail = (Outlook.MailItem)mailApplication.CreateFromTemplate(“temp.msg”);