Get Outlook's Internet Headers using VBA

Last reviewed on December 27, 2012

Use this code sample and function to display the Internet header of selected message in a new message form.

Tested in Outlook 2013, also works in Outlook 2010 and 2007. For Outlook 2003 and older, see Get Internet header VBA code sample for Outlook 2003.


Sub ViewInternetHeader()
    Dim olkItm As Outlook.MailItem, olkFwd As Outlook.MailItem
    Dim strheader As String

    For Each olkItm In Application.ActiveExplorer.Selection
        strheader = GetInetHeaders(olkItm)
    
        Set olkFwd = Application.CreateItem(olMailItem)
        With olkFwd
            .BodyFormat = olFormatPlain
            .Body = strheader
            .Display
        End With
    Next
    Set olkFwd = Nothing
End Sub


Function GetInetHeaders(olkMsg As Outlook.MailItem) As String
    ' Purpose: Returns the internet headers of a message.'
    ' Written: 4/28/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: 2007'
    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim olkPA As Outlook.PropertyAccessor
    Set olkPA = olkMsg.PropertyAccessor
    GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS)
    Set olkPA = Nothing
End Function

More Information

Retreiving Internet Headers Using VBA in Outlook 2007/2010 Includes a code sample to use with Run a Script rule.

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999 and involved in IT support since 1985, Diane is the author of several books and video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.