Can I modify Conversation ID in Outlook by VBA to group independent Emails?
Asked Answered
L

2

14

I do receive a lot of mails sent by various robots. I can identify Emails easily by subject (for example: "Response to ticket 123"). Unfortunately each email is generated automatically, individually.

For this Outlook does not Group them as an ordinary conversation does.

I wonder if it is possible to modify for example the mail property "ConversationID"? Do I Need to create a "ConversationTopic" and assign it to the related MailItems?

Luminosity answered 20/11, 2015 at 22:7 Comment(3)
Could you post the script you have so far?Eckert
I wrote a program once to go through the inbox and archive everything into folders by matching certain strings in the subject or sender etc. Similar sort of application. Something to consider.Herbarium
Possible duplicate of How can I modify conversationTopic so emails with different subjects are put in the same thread?Vitriolize
D
6

I was able to solve this myself by using Redemption to get write-access to the MAPI properties of ConversationTopic and ConversationIndex.

While apparently ConversationTopic is used at first for grouping messages, also ConversationIndex plays a role in grouping: It does not only carry the sorting time stamp, but the first bytes are a conversation code that must match across all emails of a conversation. Otherwise they are still not grouped, even with same topic. See here for details: https://msdn.microsoft.com/en-us/library/ms528174(v=exchg.10).aspx

Luckily, setting the Index to Null apparently makes Outlook pay attention only to the topic, so we don't need to re-calculate a new index.

My working code:

Dim oNS As Object
Dim oRDOSess As Object
Dim oRDOItem As Object

Debug.Print "Creating Redemption Object ..."
' This requires: http://www.dimastr.com/redemption/download.htm
Set oRDOSess = CreateObject("Redemption.RDOSession")
Set oNS = Nothing
Set oNS = Outlook.GetNamespace("MAPI")
oNS.Logon
oRDOSess.MAPIOBJECT = oNS.MAPIOBJECT

Set oRDOItem = oRDOSess.GetMessageFromID(incomingMail.EntryID, incomingMail.Parent.StoreID)

Debug.Print "Trying to change conversation topic ..."
oRDOItem.ConversationTopic = incomingMail.Subject

Debug.Print "Trying to change conversation index ..."
oRDOItem.Fields("http://schemas.microsoft.com/mapi/proptag/0x00710102") = Null

Debug.Print "Saving modified mail item ..."
oRDOItem.Save
Diamond answered 29/1, 2016 at 18:21 Comment(0)
A
4

Edit: Per User Glen K in the comments, the missing part is saving the message after making the update. I have added this save to the code as noted, but do not have time to test this. With the addition, this would be a complete answer, but as it is untested, I am leaving the original post, including comments stating that it doesn't entirely work, with the only change being the updated save.

This is not a complete answer, but it is too long for a comment.

I was able to set the MAPI conversationTopic and conversationIndex properties using the tips here and the code:

 oItem.propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x00710102", _
             oItem2.propertyAccessor.GetProperty("http://www.slipstick.com/developer/read-mapi-properties-exposed-outlooks-object-model/")

for the ConversationIndex property, for example. This assumes that you have one message as oItem and the other as oItem2, both declared as Objects. Note that this property is binary, and so if you want to look at it you can use:

 oItem2.propertyAccessor.BinaryToString(x)

where x represents the property (set to a variable or just put the propertyAccessor.GetProperty code in there). This becomes relevant because the ConversationID of the message object is the last bunch of "characters/binary bits" of the MAPI ConversationIndex property. However, changing the ConversationIndex property DID NOT change the ConversationID.

Both the ConversationIndex and conversationTopic properties of the message object are read-only, however changing the conversationTopic MAPI property DID change the ConversationTopic property of the message. I was unable to get this to actually group the messages, however.

My research suggested that the ConversationTopic property should be the one that initially groups the messages, with the ConversationIndex property sorting them after the grouping, but, as I mentioned, I was unable to get the messages to group, even after assigning the same ConversationTopic to both MAPI and the message object.

Here's code that helps show this behavior:

Dim Msg As Outlook.MailItem
Dim oItem As Object
Dim oItem2 As Object
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim Item As Object

Set objNS = GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)


For Each Item In olFolder.Items
    If TypeName(Item) = "MailItem" Then
        Debug.Print "Subject: " & Item.Subject & " " & Item.propertyAccessor.BinaryToString(Item.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102"))
    
        If Item.Subject = "test" Then
            Set oItem = Item
        ElseIf Item.Subject = "test2" Then
            Set oItem2 = Item
        End If
    End If
Next Item

Debug.Print "OItem: " & vbCr _
            & "ConversationIndex: " & oItem.ConversationIndex & vbCr _
            & "ConversationID: " & oItem.ConversationID & vbCr _
            & "ConversationTopic: " & oItem.ConversationTopic & vbCr _
            & "MAPI ConversationIndex: " & oItem.propertyAccessor.BinaryToString(oItem.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")) & vbCr _
            & "MAPI ConversationTopic: " & oItem.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001E") & vbCr
            

Debug.Print "OItem2: " & vbCr _
            & "ConversationIndex: " & oItem2.ConversationIndex & vbCr _
            & "ConversationID: " & oItem2.ConversationID & vbCr _
            & "ConversationTopic: " & oItem2.ConversationTopic & vbCr _
            & "MAPI ConversationIndex: " & oItem2.propertyAccessor.BinaryToString(oItem2.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")) & vbCr _
            & "MAPI ConversationTopic: " & oItem2.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001E") & vbCr
            
Debug.Print "Set OItem2 To OItem"

oItem2.propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x0070001E", oItem.ConversationTopic
oItem2.propertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x00710102", oItem.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")
oItem2.save

Debug.Print "OItem: " & vbCr _
            & "ConversationIndex: " & oItem.ConversationIndex & vbCr _
            & "ConversationID: " & oItem.ConversationID & vbCr _
            & "ConversationTopic: " & oItem.ConversationTopic & vbCr _
            & "MAPI ConversationIndex: " & oItem.propertyAccessor.BinaryToString(oItem.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")) & vbCr _
            & "MAPI ConversationTopic: " & oItem.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001E") & vbCr
            

Debug.Print "OItem2: " & vbCr _
            & "ConversationIndex: " & oItem2.ConversationIndex & vbCr _
            & "ConversationID: " & oItem2.ConversationID & vbCr _
            & "ConversationTopic: " & oItem2.ConversationTopic & vbCr _
            & "MAPI ConversationIndex: " & oItem2.propertyAccessor.BinaryToString(oItem2.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")) & vbCr _
            & "MAPI ConversationTopic: " & oItem2.propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001E") & vbCr

Sharing this in case it helps anyone solve the problem.

Aminoplast answered 28/1, 2016 at 21:12 Comment(5)
This is an old thread, but I may need the binarytostring to solve my problem, do you know how could I use it on the row item? My full question is here in case you want to know my backgroundLatoyia
@Latoyia Unfortunately, I don't know how to do this and don't have the time to research it at the moment. I used to work in a position that heavily used VBA, but now work in one where I barely use it at all so I'm a bit rusty. Good luck!Aminoplast
This is an old thread, but this should be the correct answer. Using Redemption does work, but it's not free unless you don't mind the prompt with the free license. Not to mention you cannot modify ConversationID with this method, either Redemption. Modifying ConversationIndex is good enough. I tried to modify both ConversationIndex and ConversationTopic, they both worked.Titanate
This answer worked for me with one change required. It needs oItem2.Save at the end of the code.Needlepoint
@GlenK Thanks! I've added and noted your solution in the answer.Aminoplast

© 2022 - 2024 — McMap. All rights reserved.