0 votes
by (240 points)

Is there any chance to get the conversationId of an email? I am currently getting an MailMessage and EwsMessageInfo back.

Do you have a recommended approach for receiving the conversationId?

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (73.6k points)

The ConversationId cannot be read from the EwsMessageInfo object directly, but you can read the value from XML representation of the EwsMessageInfo object.

Use the EwsMessageInfo.ToXml() method and locate required nodes. It can be done for example like this:

// get the first 10 items from INBOX
var list = client.GetMessageList(EwsFolderId.Inbox, EwsItemFields.Full, EwsPageView.CreateIndexed(0, 10));

foreach (var item in list)
{
    // load EWS item to a XML
    var xml = new XmlDocument();
    xml.LoadXml(item.ToXml());

    // get the namespace in use
    var xmlns = new XmlNamespaceManager(xml.NameTable);
    xmlns.AddNamespace("n", xml.DocumentElement.NamespaceURI);

    // look for node like <t:ConversationId Id="_VALUE_" />
    var conversationId = xml.DocumentElement.SelectSingleNode("//n:ConversationId", xmlns);
    if (conversationId == null)
        Console.WriteLine("Message ConversationId is not present.");
    else if (conversationId.Attributes["Id"] == null)
        Console.WriteLine("Message ConversationId.Id is not present.");
    else 
        Console.WriteLine("Message ConversationId: {0}", conversationId.Attributes["Id"].Value);

    // look for node like <t:ConversationTopic>_VALUE_</t:ConversationTopic>
    var conversationTopic = xml.DocumentElement.SelectSingleNode("//n:ConversationTopic", xmlns);
    if (conversationTopic == null)
        Console.WriteLine("Message ConversationTopic is not present.");
    else
        Console.WriteLine("Message ConversationTopic: {0}", conversationTopic.InnerText);

    // look for node like <t:ConversationIndex>_VALUE_</t:ConversationIndex>
    var conversationIndex = xml.DocumentElement.SelectSingleNode("//n:ConversationIndex", xmlns);
    if (conversationIndex == null)
        Console.WriteLine("Message ConversationIndex is not present.");
    else
        Console.WriteLine("Message ConversationIndex: {0}", conversationIndex.InnerText);
}
...