Last reviewed on March 9, 2015   —  6 Comments

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

Read Internet Header

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 olItem As Outlook.MailItem, olMsg As Outlook.MailItem
    Dim strheader As String

    For Each olItem In Application.ActiveExplorer.Selection
        strheader = GetInetHeaders(olItem)
    
        Set olMsg = Application.CreateItem(olMailItem)
        With olMsg 
            .BodyFormat = olFormatPlain
            .Body = strheader
            .Display
        End With
    Next
    Set olMsg = 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'
    ' http://techniclee.wordpress.com/
    ' 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

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

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


Comments

  1. kixtart says

    I'm 100% ignorant of how to even start this process. Do I begin by opening Notepad, and pasting the above code into a new txt file? Then what? I'm a sysadmin and have only done batch file scripting up to this point, somehow. Please don't blast me for that. :-)

    • Diane PoremskyDiane Poremsky says

      What are you trying to do? How is it not working? This macro just grabs the internet header and puts it in a message body so it's easy to read.

  2. Simon Lukes says

    Hi Diane,

    I am trying to clarify the workings of the GetInetHeaders function. Is it using an xml schema from a microsoft website to pull out the header information? I did pop over to the website referred to in the code but it doesn't appear to be searcheable and I couldn't (didn't know how to) search for that particular example of BlueDevilFan's code to see if it was explained.

Leave a Reply

Please post long or more complicated questions at OutlookForums by Slipstick.com.

If the Post Comment button disappears, press your Tab key.