locked
How to Search Outlook Mail Body? RRS feed

  • Question

  • Hi,

    I wrote an Add-in with Outlook which has to search all the outlook (or selected outlook folders') mails Subject or Body, by the keywords from my SQL Server Table. Assume I've 10 Names in my Employee Table. I've to search the mails which are all having at least one of the Employee names from my Table in either Subject or Body. I can search the Subject by "urn:schemas:mailheader:subject = 'Kannan'". But I want to search with in Body too. Is it possible with this Integrated Outlook Advanced Search method, or I've to write separate routine? Any suggestions / sample codes will be appreciated.

    Thanks in Advance,

    Tuesday, August 15, 2006 5:31 AM

Answers

  • You can use the following namespace for the same

    urn:schemas:httpmail:textdescription to search inside the text body of the mail

    or

    urn:schemas:httpmail:htmldescription to search inside the html body of the mail

    following is the sample you can run from inside Outlook's VB Editor

    Sub SearchInboxFolder()
      Dim objSch As Search
      Dim strF As String
      Dim strS As String
      Dim strT As String
      Dim strTag As String
       
      strS = "Inbox"
      strT = InputBox("Enter the body text.", "Search Criteria")
      strF = "urn:schemas:httpmail:textdescription LIKE '%" & strT & "'"
      strTag = "BodySearch"
     
      Set objSch = Application.AdvancedSearch(strS, strF, False, strTag)
    End Sub


    Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
      Dim objResults As Results
      Set objResults = SearchObject.Results
      Dim objResult As Object
     
      MsgBox "AdvancedSearch found : " & objResults.Count
     
      For Each objResult In objResults
        Debug.Print objResult.Subject
      Next
    End Sub

    Refer to the following URLs

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/75d4e31f-9fc5-479f-bb14-019eec47fda3.asp

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/dbca4fb9-afcb-4716-9e0c-4bff45ca0b60.asp

     

    Tuesday, August 15, 2006 6:55 PM
  • Hello,

    You might also check out the following topic on MSDN for searching mails for text http://msdn2.microsoft.com/en-us/library/ms268869.aspx. This topic refers to the subject of the mail.  Try using this code sample and subsituting [Subject] for [Body].

    Thursday, August 17, 2006 8:38 PM
    Answerer

All replies

  • You can use the following namespace for the same

    urn:schemas:httpmail:textdescription to search inside the text body of the mail

    or

    urn:schemas:httpmail:htmldescription to search inside the html body of the mail

    following is the sample you can run from inside Outlook's VB Editor

    Sub SearchInboxFolder()
      Dim objSch As Search
      Dim strF As String
      Dim strS As String
      Dim strT As String
      Dim strTag As String
       
      strS = "Inbox"
      strT = InputBox("Enter the body text.", "Search Criteria")
      strF = "urn:schemas:httpmail:textdescription LIKE '%" & strT & "'"
      strTag = "BodySearch"
     
      Set objSch = Application.AdvancedSearch(strS, strF, False, strTag)
    End Sub


    Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
      Dim objResults As Results
      Set objResults = SearchObject.Results
      Dim objResult As Object
     
      MsgBox "AdvancedSearch found : " & objResults.Count
     
      For Each objResult In objResults
        Debug.Print objResult.Subject
      Next
    End Sub

    Refer to the following URLs

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/75d4e31f-9fc5-479f-bb14-019eec47fda3.asp

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/dbca4fb9-afcb-4716-9e0c-4bff45ca0b60.asp

     

    Tuesday, August 15, 2006 6:55 PM
  • Hello,

    You might also check out the following topic on MSDN for searching mails for text http://msdn2.microsoft.com/en-us/library/ms268869.aspx. This topic refers to the subject of the mail.  Try using this code sample and subsituting [Subject] for [Body].

    Thursday, August 17, 2006 8:38 PM
    Answerer