Retrieving all Outlook messages in same thread

2019-05-30 06:12发布

问题:

We are building sort of Communication Management System atop Outlook. One of the important task we wish to achieve is to retrieve all the messages (.msg files??) in the same thread along with their attachments and put them in the same folder inside CMS's repository .

The problem we are facing is how do we know programatically that particular message (or .msg file??) and attachment belongs to the particular thread.

Say for a first message we create a folder in a repository. Then we want all the messages (along with attachments) sent as a reply to the original message to go automatically in the same folder.

I tried to find if their is any header set in .msg file to identify the thread, but did not found anything.

But still curious how the Outlook client can show the messages arranged as communication thread hierarchy. So there must be some way that we can retrieve this information stored somewhere. I just want to know how can I access it.

回答1:

Use PR_CONVERSATION_INDEX property (you can see it in OutlookSpy if you click the IMessage button)
Conversation tracking is documented on MSDN: http://msdn.microsoft.com/en-us/library/office/cc765583.aspx



回答2:

The grouped conservation are indicated in the message header: "Message-ID: ", "References: " & "In-Reply-To: ", you can view it with Outlook VBA with below function I found previously.

Private Function GetInetHeaders(olkMsg As Outlook.MailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As Outlook.PropertyAccessor
    Set olkPA = olkMsg.PropertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function