'To filter mails from inbox which are sent to another recipient?
In Outlook Interop,
using Outlook = Microsoft.Office.Interop.Outlook;
To filter unread emails, I'm using the following code
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace outlookNameSpace = oApp.Application.GetNamespace("MAPI");
Outlook.MAPIFolder inbox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items items = inbox.Items.Restrict("[Unread]=true");
Likewise, Is there a way to filter the mails sent to a specific recipient other than me.
Say, filter mails sent to [email protected].
My mail ID would also be present in those mails in To or in CC. I will be happier to find a possible way with Outlook interop.
Solution 1:[1]
You can use a search query like the following to search for a match on the PR_DISPLAY_TO MAPI property (replace 0x0E04001F with 0x0E03001F for PR_DISPLAY_CC)
@SQL="http://schemas.microsoft.com/mapi/proptag/0x0E04001F" LIKE '%[email protected]%'
Keep in mind however that PR_DISPLAY_TO / PR_DISPLAY_CC may or may not contain the email addresses; they could just contain display names.
On the Extended MAPI level (C++ or Delphi), you can create a restriction on recipients (RES_SUBRESTRICTION / PR_MESSAGE_RECIPIENTS).
If using Redemption (I am its author - any language) is an option, you can use RDOFolder.Items.Restrict - unlike Outlook Object Model, it does expand To/CC/BCC queries into recipient sub restrictions on PR_DISPLAY_NAME and PR_EMAIL_ADDRESS properties on each recipient (RES_SUBRESTRICTION / PR_MESSAGE_RECIPIENTS / RES_OR / PR_DISPLAY_NAME | PR_EMAIL_ADDRESS).
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Folder = Session.GetFolderFromID(Application.ActiveExplorer.CurrentFolder.EntryID)
set restrItems = Folder.Items.Restrict(" TO = '[email protected]' ")
You can also specify Recipients property in a query - it will be matched against recipients of all types (to/cc/bcc):
set restrItems = Folder.Items.Restrict(" Recipients = '[email protected]' ")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
