Finding Conversation ID from GetOutlookEmail Activity output mailmessages

Hello All,
We have a requirement to find email thread and map any new email to existing email, like we see in Outllook emails are grouped as conversation.

Please note we can not find email conversation based on subject or sender as it can be same for different conversation threads.
I see C# has mailItem.conversationID property however I don’t see that in UiPath Mailmessage.Headers or any other properties. Is there a way to find if two emails are part of same conversation thread by using any unique header or other property in UiPath?

I’d be glad to help you with finding the Conversation ID from GetOutlookMailMessages activity output in UiPath. However, there isn’t a direct equivalent of mailItem.conversationID property available in MailMessage objects.

Here are alternative approaches you can consider:

1. Leveraging Message Thread ID (if applicable):

  • If your Outlook server supports the Thread-ID header (common in IMAP servers), you might be able to use it to group emails.
  • Check the Headers collection of the MailMessage object for the presence of the Thread-ID header.
  • If it exists, use it to group emails together. However, be aware that Thread-ID might not be universally consistent or reliable.

2. Combining Subject, Sender, and Received Date (heuristic approach):

  • Create a custom logic to combine Subject, Sender, and ReceivedTime properties.
  • This approach can work reasonably well for basic scenarios but might not be foolproof for complex email threads with variations in subject or sender.

3. Custom Implementation with Outlook API (more advanced):

  • If you have more control over the environment and require a robust solution, consider using the Outlook API directly within UiPath.
  • The API provides access to the ConversationId property, which can accurately group emails.
  • This approach requires development effort and knowledge of the Outlook API.

Here’s a possible implementation using approach 2 (assuming Headers collection has Thread-ID):

// Group emails by Thread-ID (if available)
var threadGroups = mailMessages.GroupBy(message => message.Headers["Thread-ID"]?.ToString());

// Process each thread group
foreach (var group in threadGroups)
{
    // Access emails within the same thread
    var emailsInThread = group.ToList();
    // ... your logic to process emails in the thread
}

If Thread-ID is unavailable, consider approach 2:

// Group emails by a combination of Subject, Sender, and ReceivedTime (heuristic)
var threadGroups = mailMessages.GroupBy(message =>
    new { Subject = message.Subject, Sender = message.Sender.EmailAddress, ReceivedTime = message.ReceivedTime });

// Process each thread group (similar to the previous approach)

Remember that approach 2 might not be perfect, so test it thoroughly with your specific email patterns.

If you need more advanced conversation grouping or have control over the environment, explore using the Outlook API within UiPath.