![](/img/trans.png)
[英]Outlook VBA - Move only emails from conversation that are still in inbox
[英]Can I modify Conversation ID in Outlook by VBA to group independent Emails?
我確實收到了很多由各種機器人發送的郵件。 我可以通過主題輕松識別電子郵件(例如:“對工單 123 的響應”)。 不幸的是,每封電子郵件都是單獨自動生成的。
為此,Outlook 不會像普通對話那樣將它們分組。
我想知道是否可以修改例如郵件屬性“ConversationID”? 我是否需要創建一個“ConversationTopic”並將其分配給相關的 MailItems?
通過使用Redemption獲得對 ConversationTopic 和 ConversationIndex 的 MAPI 屬性的寫訪問權限,我能夠自己解決這個問題。
雖然顯然 ConversationTopic 首先用於對消息進行分組,但 ConversationIndex 在分組中也起作用:它不僅攜帶排序時間戳,而且第一個字節是對話代碼,必須在對話的所有電子郵件中匹配。 否則,即使主題相同,它們仍然沒有分組。 有關詳細信息,請參見此處: https : //msdn.microsoft.com/en-us/library/ms528174(v=exchg.10).aspx
幸運的是,將 Index 設置為 Null 顯然使 Outlook 只關注主題,因此我們不需要重新計算新的索引。
我的工作代碼:
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
這不是一個完整的答案,但評論太長了。
我能夠使用此處的提示和代碼設置 MAPI 對話主題和對話索引屬性:
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/")
例如,對於 ConversationIndex 屬性。 這假設您將一條消息作為 oItem,將另一條消息作為 oItem2,兩者都聲明為對象。 請注意,此屬性是二進制的,因此如果您想查看它,可以使用:
oItem2.propertyAccessor.BinaryToString(x)
其中 x 表示屬性(設置為變量或只是將 propertyAccessor.GetProperty 代碼放在那里)。 這變得相關,因為消息對象的 ConversationID 是 MAPI ConversationIndex 屬性的最后一組“字符/二進制位”。 但是,更改 ConversationIndex 屬性並沒有更改 ConversationID。
消息對象的ConversationIndex 和conversationTopic 屬性都是只讀的,但是更改conversationTopic MAPI 屬性會更改消息的ConversationTopic 屬性。 但是,我無法將其實際分組。
我的研究表明 ConversationTopic 屬性應該是最初對消息進行分組的屬性,ConversationIndex 屬性在分組后對它們進行排序,但是,正如我所提到的,即使在將相同的 ConversationTopic 分配給后,我也無法將消息分組MAPI 和消息對象。
這是有助於顯示此行為的代碼:
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
分享這個以防萬一它可以幫助任何人解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.