Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Getting Email Headers in Outlook

Getting Email Headers in Outlook

Scheduled Pinned Locked Moved Visual Basic
toolshelpquestioncareer
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    u6ik
    wrote on last edited by
    #1

    I've been trying to obtain the email header from messages in Outlook using VBA. I have done some investigation and found that in outlook they are stored separately and require use of the CDO library to get hold of the header. So, I used Tools-Reference to enable the CDO Win 2000 library, cdosys.dll and employed the code below - but on compiling in the Outlook VBA Editor it gives me errors in all references to that CDO library. Can anyone assist here? Many thanks ;) Public Function InternetHeaders() As String Dim objOutlook As Outlook.Application Dim objItem As Outlook.MailItem Dim objCDO As MAPI.Session Dim objMessage As MAPI.Message Dim objFields As MAPI.Fields Dim strID As String Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E On Error Resume Next ' Instantiate an Outlook Application object. Set objOutlook = CreateObject("Outlook.Application") 'Find the current email item and get its EntryID Set objItem = objOutlook.ActiveInspector.CurrentItem strID = objItem.EntryID 'Then set up a CDO Session using a piggy-back login Set objCDO = CreateObject("MAPI.Session") objCDO.Logon "", "", False, False 'Now get the item as a CDO Message Set objMessage = objCDO.GetMessage(strID) 'Now get the headers from the message Set objFields = objMessage.Fields InternetHeaders = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value 'Now that the headers are captured in a string you can do whatever you want with them objCDO.Logoff Set objFields = Nothing Set objMessage = Nothing Set objCDO = Nothing Set objItem = Nothing Set objOutlook = Nothing End Function

    u6ik

    U 1 Reply Last reply
    0
    • U u6ik

      I've been trying to obtain the email header from messages in Outlook using VBA. I have done some investigation and found that in outlook they are stored separately and require use of the CDO library to get hold of the header. So, I used Tools-Reference to enable the CDO Win 2000 library, cdosys.dll and employed the code below - but on compiling in the Outlook VBA Editor it gives me errors in all references to that CDO library. Can anyone assist here? Many thanks ;) Public Function InternetHeaders() As String Dim objOutlook As Outlook.Application Dim objItem As Outlook.MailItem Dim objCDO As MAPI.Session Dim objMessage As MAPI.Message Dim objFields As MAPI.Fields Dim strID As String Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E On Error Resume Next ' Instantiate an Outlook Application object. Set objOutlook = CreateObject("Outlook.Application") 'Find the current email item and get its EntryID Set objItem = objOutlook.ActiveInspector.CurrentItem strID = objItem.EntryID 'Then set up a CDO Session using a piggy-back login Set objCDO = CreateObject("MAPI.Session") objCDO.Logon "", "", False, False 'Now get the item as a CDO Message Set objMessage = objCDO.GetMessage(strID) 'Now get the headers from the message Set objFields = objMessage.Fields InternetHeaders = objFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value 'Now that the headers are captured in a string you can do whatever you want with them objCDO.Logoff Set objFields = Nothing Set objMessage = Nothing Set objCDO = Nothing Set objItem = Nothing Set objOutlook = Nothing End Function

      u6ik

      U Offline
      U Offline
      u6ik
      wrote on last edited by
      #2

      Okay. It looks like the issue is that in Outlook VBA with the CDO library referenced, I get the error 'Activex component can't create object'. The line that fails is: Set CDOSession = CreateObject("MAPI.Session") Any ideas?

      u6ik

      U 1 Reply Last reply
      0
      • U u6ik

        Okay. It looks like the issue is that in Outlook VBA with the CDO library referenced, I get the error 'Activex component can't create object'. The line that fails is: Set CDOSession = CreateObject("MAPI.Session") Any ideas?

        u6ik

        U Offline
        U Offline
        u6ik
        wrote on last edited by
        #3

        Problem solved. The CDO is not installed as standard in Outlook 2003! After an update all works fine.

        u6ik

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups