Search Folders for arbitrary email headers in Outlook

Solution 1:

I was trying to do the same recently and in searching the web encountered your question. I too failed to find any way to use the search folder to check headers. My assumption is because internet headers aren't really an "Exchange field", meaning that I don't believe any "intranet" email sent within the Exchange server itself (like that email you sent with the funny cat picture [LOLZ!] to your co-worker...) has such headers. But here is the workaround I came up with that I'm using.

I set up a new rule in the rules wizard that on receipt of new messages to check the headers. If a specific string is found then assign the message to a specific category. In my case I'm looking for messages that come from our Best Practical Request Tracker server, in each of those headers is the string "RT-ticket:". If my rules find this string in the header they then assign the message to a category I created named "RT Tickets". (I created this category with no color so it is less obtrusive.) I can then create a search folder that looks for messages of just that category. Extra steps but problem solved. I've done this in Outlook 2007 but it should work in any version of Outlook that supports the rules wizard checking headers and then assigning to categories.

The drawbacks to this are 1) yet another rule in my growing list, and 2) if I want to apply this to emails already received I'll need to go through and manually run the rule against those folders first. At this point I'm only concerned about new messages presently in my inbox or those arriving going forward so I simply set the rule to run at the time of creation and that was taken care of. A discovered benefit of using the categories though is that you can have it display as a column in your message list. I'm not sure I'll even be using the search folders as I had intended, I may just go and sort my inbox by category in order to find the desired messages.

If anyone needs the steps of creating a rule expanded I can do so, just leave a comment. I would hope though that if one is knowledgeable enough to be digging around in internet email headers that creating an Outlook rule would be old-hat. The wizard they have is pretty straightforward.

Solution 2:

This PowerShell script searches all headers in Inbox for a match. It may take a while to run, depending on your inbox size. Some caveats apply, not the least of which is a possible residual outlook.exe process. This could be killed either manually in Task Manager, or programmatically via get-process "outlook" | kill. It's assumed you have access to PoweShell because of its near ubiquity, however the particular OS you are using could have limited support for this.

$MatchString = "X-Mailer: YahooMailWebService/0.8.201.700"
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$namespace = new-object -comobject outlook.application
$MAPI = $namespace.GetNamespace("MAPI")
$Inbox = $MAPI.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox).Items
$Headers = `
    foreach ( $MailItem in $Inbox ) { 
        $MailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") 
    }
$namespace.Quit()
$MatchingHeaders = $Headers | where { $_.contains( $MatchString ) }
#sample output
$MatchingHeaders | Select-Object -First 1

If there is a nonzero set of matches, something like the following is returned.

Received: from q0plumsmtp03-06.purd.phy5.mysrver.net (68.178.213.11) by q0PWrc6HT002.rc6.mysrver.net (148.168.131.21) with Microsoft SMTP Server id 14.2.18.1; Wed, 13 Aug 2014 18:42:57 -0700 [...]

You can then change the $MatchString assignment to the header string you're looking for. If you want to generalize the search using regular expressions, PowerShell makes that possible too.