Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access an Outlook message using a unique and stable identifier?

I'm building an application that analyzes Outlook email messages, stores the analyzed information, and later allows the user to open messages meeting certain criteria.

I expected that I would extract the Message-ID from each email, store this in my database, and then ask Outlook to open up a message by providing it with the Message-ID at a later point. However, it would seem that I'm missing something.

Via the Outlook interop APIs, I can get an EntryID, but as far as I can tell, an EntryID is only guaranteed to be stable within a given folder (or maybe a given store). If a message is moved to a different folder, the EntryID may change. Additionally, the APIs require that the StoreID is provided when looking up a message by EntryID. Again, if a message is moved between stores, that information will presumably be invalid.

I've seen plenty of Office-related products that seem to do something like what I've described above. How can I do an efficient look-up of a message that is accessible to Outlook, regardless of stores etc.?

Currently, my back-up plan is to store EntryID and StoreID information for each Message-ID that I scan, and then try all the various EntryID / StoreID combos that I've recorded for a given MessageID until one is successful. But this seems like work that Outlook should already know how to accomplish for me.

Thanks,

-Patrick

like image 536
Patrick Linskey Avatar asked Nov 06 '22 11:11

Patrick Linskey


1 Answers

"But this seems like work that Outlook should already know how to accomplish for me"

It should. But it doesn't. At least, when I used the API, I didn't find any obvious one. Maybe the reason is quite simple: Message-ID is meaningless for Outlook itself, so saving it as a property was never implemented in the product.

Now, I think the most obvious way is to do the thing you are already doing, ie. storing associations between Message-ID and StoreID - EntryID pair. This will let you access the desired e-mail quickly without walking through the list of every stored mail. Now, you must obviously check if the Message-ID is still correct, and if it is not, looping through every mail.

By the way, I don't understand well why are you storing several StoreID - EntryID pairs for each Message-ID. I suppose that the mail would be stored only once in Outlook, so one pair per Message-ID is enough. When this pair is obsolete (mail moved to another folder/store), you just update it.

Note: wouldn't it be easier and faster to access CreationTime and MailItem.SenderEmailAddress properties? It would be strange to see two different mails sharing those properties, so it is somehow a way to uniquely identify a mail, without having to extract manually the Message-ID.

like image 75
Arseni Mourzenko Avatar answered Nov 15 '22 00:11

Arseni Mourzenko