Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vba

outlook

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?

like image 629
Volker Avatar asked Nov 20 '15 22:11

Volker


People also ask

How do I group emails by conversation in Outlook?

Set your emails to Conversation View Open Outlook. In the View tab at the top of the screen, check the Show as Conversations box. This will group together emails by conversation. You can play around with the Conversation Settings to find what works best for you.

How does Outlook define a conversation?

By default, when you add most account types to Outlook, your messages are displayed in Conversations. A conversation includes all messages in the same thread with the same subject line.


2 Answers

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
like image 99
djk Avatar answered Oct 29 '22 11:10

djk


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")

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.

like image 26
OpiesDad Avatar answered Oct 29 '22 10:10

OpiesDad