We help IT Professionals succeed at work.
Get Started

Outlook VBA how to scan email headers

Mark asked
Last Modified: 2016-02-11
I'm trying to made an Outlook VB module to scan through an email's header for a particular header. For example, given the headers:
From: "Dan Simon" <dsimon@xxx.com>
To: "'Matt Gregory'" <MGREGORY@yyy.com>
Cc: "'Lucy'" <bthrock4@zzzl.com>
References: <004a01cfaf57$5a4ec140$0eec43c0$@apex-title.com>    <CA+59raJ69dK7C5uyyvztMs=7iDNw-wkPoSC0gbcRyecAY
p8bKg@mail.gmail.com>   <CABLLg6=dfpMttb5HbvxZ+GbPzLRx37cxKpcSOichhFCCVDT7Sw@mail.gmail.com>    <f7577a674c7b47
8eb538fa0ad75cdce9@CSC-EX13-01.cscloud.priv>    <007b01cfb111$94314110$bc93c330$@apex-title.com>        <72de16
bde0304b42b16a7d1d21478985@CSC-EX13-01.cscloud.priv>    <FC177A271ECF104D8FECF73F8795FE8B32D3FAC060@MAIL.hprs.l
ocal>,<CAG7ouXd_DPAnTMoxqPOwvjjQQ7529KH1s_4jNmOi36Lm4Y4k8A@mail.gmail.com> <28144A4F-8CE1-4AC8-BF61-A919F8D69CE
3@ohioequities.com>,<019b01cfb5a2$6dbb3af0$4931b0d0$@apex-title.com> <658FD438-1257-4728-B603-2D64F444E952@ohio
In-Reply-To: <658FD438-1257-4728-B603-2D64F444E952@ohioequities.com>
Subject: RE: 6500 Busch Boulevard, Columbus, OH 43229 - Updated Commitment and Draft HUD
Date: Tue, 12 Aug 2014 09:24:42 -0500
Keywords: Red Category
Message-ID: <003c01cfb639$2933de90$7b9b9bb0$@apex-title.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;
X-Mailer: Microsoft Office Outlook 12.0
X-Virus-Status: Clean
X-Virus-Scanned: clamav-milter 0.98.1 at webserver
X-Spam-Status: No, score=0.0 required=3.0 tests=HTML_MESSAGE,   RCVD_IN_DNSWL_NONE autolearn=disabled version=3
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on webserver.ohprs.org
Thread-Index: AQEhggqaBNb5ghRXTh9S+faTbwOVOgJhrekRAgxwxSwCS9PzwwIjJokmA1Ot+fkCCGD68QIZo2iuAoEZoiEBvag7SgIuePaXn
Content-Language: en-us
x-ms-exchange-organization-authas: Internal
x-ms-exchange-organization-authsource: MAIL.hprs.local
X-OlkEid: B1044D21BD509E663B48F84C9AA4C079FDE11715
x-ms-exchange-organization-authmechanism: 10
x-vipre-scanned: 4AADA05C007F564AADA1A9

This is a multi-part message in MIME format.

Content-Type: multipart/alternative;

Content-Type: text/plain;
Content-Transfer-Encoding: 8bit

Open in new window

I'd like to scan through looking for the header "Keywords: Red Category" (line 14). I've looked at an example at http://www.slipstick.com/developer/read-mapi-properties-exposed-outlooks-object-model/, but I don't know if this "Schema" method is going to work for me as the "Complete List" of Email Messages Properties doesn't appear to have one for "Keywords", nor does it appear to have a bunch of others such as spam headers.

I've got the following code going, but am kind of stuck. Help?
Public Sub scanFolder()
Dim src As Folder
Dim oItem As Object
Dim propertyAccessor As Outlook.propertyAccessor
Set src = Application.ActiveExplorer.CurrentFolder
Dim cnt As Integer
Dim strHeader As String
cnt = 0

For Each oItem In src.Items
    If TypeOf oItem Is Outlook.MailItem Then
        Set propertyAccessor = oItem.propertyAccessor
        Debug.Print propertyAccessor.GetProperty("schemaName???") ' what goes here?
        cnt = cnt + 1
    End If
Debug.Print cnt
End Sub

Open in new window

Watch Question
IT Manager
This problem has been solved!
Unlock 2 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE