0
votes

I'm developing an application that tracks exchange email messages in our company. We where able to get info out from the tracking log, but in the log -by design- there is no subject or body message. So the next step for us was using EWS to get the message detail when needed. The question is that in the tracking log we find to IDs :

MessageId in format "F533E7F015A2E24F8D8ABFE2587117C601EDF245@blstex02.subdomain.domain.com"

and

InternalMessageId in format "5840818"

If in EWS we use this id to find the message by id we always get an "Id is malformed." exception. Here is the code we use:

public static EmailMessage GetEmailById(string uNameToImpersonate, string StringItemId)
        {
            return EmailMessage.Bind(GetService(uNameToImpersonate), new ItemId(StringItemId));
        }

I'm a newbie to EWS so maybe I'm missing something really easy... Thanks for your help

1

1 Answers

0
votes

You can only bind to a Message using the EWSId see https://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx for a more detailed discussion.For the InternetId you will need to search for messages with that particular Id using the findItem operation eg something like

  ItemView ivew = new ItemView(1);
  service.TraceEnabled = true;
  ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
  SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, "F533E7F015A2E24F8D8ABFE2587117C601EDF245@blstex02.subdomain.domain.com");
  FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew);

  foreach (Item item in iCol.Items)
  {
    Console.WriteLine(item.Subject);
  }