I'm developing a VSTO add-in for Outlook, Now I get a bounce back email, which included message ID. How can I trace the original email from this message ID in VSTO program?
VSTO - Outlook how to trace email from Message ID
628 Views Asked by user3259913 At
2
There are 2 best solutions below
0

As Eugene mentioned, you need to search for the sent message based on the PR_INTERNET_MESSAGE_ID
property. No reason to use Items.Restrict
or even Find/FindNext
- since you are expecting a single match (unless something is really wrong with your mailbox), a single call to Items.Find
is all your need.
Also keep in mind that in the cached Exchange mode PR_INTERNET_MESSAGE_ID
will not be set on the items in the Sent Items folder. To work round that, you'd need to open the Sent Items folder in the online mode (you can do that using Extended MAPI in C++/Delphi or Redemption (I am its author) in any language.
You can search for
PR_INTERNET_MESSAGE_ID
property value. TheDASL
name of the property ishttp://schemas.microsoft.com/mapi/proptag/0x1035001F
.Use the
Find
/FindNext
orRestrict
methods of theItems
class. TheRestrict
method is an alternative to using theFind
method orFindNext
method to iterate over specific items within a collection. TheFind
orFindNext
methods are faster than filtering if there are a small number of items. TheRestrict
method is significantly faster if there is a large number of items in the collection, especially if only a few items in a large collection are expected to be found.But if you need to find items from multiple folders I'd recommend using the
AdvancedSearch
method instead: