Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I am searching outlook sent items using advanced search method
namespace using Outlook = Microsoft.Office.Interop.Outlook;

Outlook._NameSpace olNs;
Outlook.MAPIFolder oSents;
Outlook.Items oItems;
Outlook._Application OutlookApp = new Outlook.Application();
Outlook.Results advancedSearchResults = null;
Outlook.Search advancedSearch = null;
C#
olNs = olApp.GetNamespace("MAPI");
oSents = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
string scope = "'" + oSents.FolderPath + "'";

C#
string ToAddress= "prasanna@zqa.com";
string advancedSearchTag = "Our first advanced search in Outlook";
string filter = "urn:schemas:httpmail:to LIKE \'%" + ToAddress+ "%\'";

C#
advancedSearch = OutlookApp.AdvancedSearch(scope, filter, false, advancedSearchTag);

advancedSearchResults = advancedSearch.Results;

C#
for (int count = advancedSearchResults.Count; count >= 1; count--)
{
    try
    {
        oMICopy = (Outlook._MailItem)advancedSearchResults[count];
        sAddress = oMICopy.Recipients[1].Address.ToString();
    }
    catch
    {
        continue;
    }
 }      



But i am not getting any items from sentItems folder.
It is showing advancedSearchResults.Count=0
how to seach SentMailItems of outlook with to-mail address.
Posted
Updated 23-Oct-16 17:07pm
v2
Comments
BillWoodruff 24-Sep-12 9:34am    
Have all the sent messages received been sent from OutLook/Exchange ?

If you enumerate the contents of the 'oSents variable ... assuming that it does hold a valid reference to the SentItems folder of Type Outlook.MAPIFolder ... what do you find ?

1 solution

You could try and put in double quotes around the schema. Also I don't see code for specifying the callback method that will be used when the advance search completes?

This link may help.

tps://msdn.microsoft.com/en-us/library/cc513841%28v=office.12%29.aspx?f=255&MSPPError=-2147217396
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900