Search code examples
pythonoutlookwin32comoffice-automation

Reply to an Outlook email in the same email history/conversation using the MessageID and Win32com module in Python


So I know how to look through the inbox (or any other folder) and find emails to reply to. However in my case, I have a .msg email file from which I extract the MessageID, and I'm looking to use win32com module to reply to that specific email.

I precisely need the sent email to appear in the same email thread/history/conversation as the email being responded to. I've tried setting the PR_IN_REPLY_TO_ID property to the MessageID of the msg file (PR_INTERNET_MESSAGE_ID) using the following code:

mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x1042001F", msg.messageId)

But this did not show the received email in the same email thread/history/conversation. My main expectation is for the received email to show like this just above the email being replied to:

enter image description here

Thank you for your help.


Solution

  • The mail object properties ConversationIndex and ConversationTopic give you an easy way to organize and display messages. Rather than simply grouping messages by subject, time received, or sender, you can show conversational relationships among messages. The ConversationTopic property is a string that describes the overall subject of the conversation. All messages within the same conversation use the same value for the ConversationTopic property. The ConversationIndex property is a hexadecimal string that you can use to represent the relationships between the messages in the thread. Each message in the conversation should have a different ConversationIndex property. Read more about that in the Working with Conversations article.

    I'd suggest checking message headers on every incoming email put into the same conversation, all the required information can be found there.