Example #1
0
        public Outlook.Search RunAdvancedSearch(string wordInSubject)
        {
            string scope  = "Inbox";
            string filter = String.Format(
                "@SQL=(\"urn:schemas:calendar:datereceived\" >= '{0:g}' " +
                "AND \"urn:schemas:mailheader:subject\" LIKE '%{1}%')", DateTime.Today.ToString("g"), wordInSubject);

            string ff1 = "urn:schemas:httpmail:datereceived >= '" + DateTime.Today.ToString("g") + "' AND " +
                         "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%' AND " +
                         "urn:schemas:mailheader:sender LIKE '%" + "*****@*****.**" + "%'";

            advancedSearch = null;
            Outlook.MAPIFolder folderInbox    = null;
            Outlook.MAPIFolder folderSentMail = null;
            Outlook.NameSpace  ns             = null;
            try {
                ns             = OApp.GetNamespace("MAPI");
                folderInbox    = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
                folderSentMail = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
                scope          = "\'" + folderInbox.FolderPath + "\',\'" + folderSentMail.FolderPath + "\'";
                advancedSearch = OApp.AdvancedSearch(scope, ff1, true, advancedSearchTag);
                OApp.AdvancedSearchComplete += Application_AdvancedSearchComplete;
                return(advancedSearch);
            }
            catch (Exception ex) {
                Console.WriteLine("\n\tException: " + ex.Message);
                return(advancedSearch);
            }
        }