We help IT Professionals succeed at work.

Export the headers from outlook to any of these:  csv, excel, access

Could you please tell me how can I export the headers of all my emails in my inbox to a csv or excel or access or txt
When I export my inbox from outlook to any of those mentioned above I don’t get the Header field
If there is no way to export the emails with headers, is there any way to export only the headers
I need the information in the headers more than anything else:

Microsoft Mail Internet Headers Version 2.0
Received: from ******** ([00.00.0.000]) by ********* with Microsoft SMTPSVC0
       Mon, 14 Jun 2010 14:55:47 +0100
Etc ....  

please help

If this can only be done by vb and if any one got the code could you please provide me with what to put in the form as I have a very basic knowledge regarding VB?

please help
Comment
Watch Question

Author

Commented:
If this can only be done by vb and if any one got the code could you please provide me with what to put in the form as I have a very basic knowledge regarding VB?
Top Expert 2010

Commented:
Hi, slamriss.

This is only possible with VB.  I can provide the code and instructions.  It'll be different procedures for 2003 and 2007.  Doing it in 2003 requires that CDO 1.21 is loaded on the computer.  Out of curiosity why do you want to export the headers?

Author

Commented:
Thank you very much for your answer
I will try your code for outlook 2003, but as I state in my previous question am not good with vb, could you please provide me the code and how to create the form that will go with it
To answer your question, I need the sender IP address and the sender email and the recipient email
Many thanks in advance
Top Expert 2010

Commented:
I'll provide instructions with the code.  Is CDO 1.21 loaded on your computer?

Author

Commented:
Do you have a link where I can download it


I found this one but am not sure if its the right one

http://www.microsoft.com/downloads/details.aspx?familyid=e17e7f31-079a-43a9-bff2-0a110307611e&displaylang=en
Top Expert 2010

Commented:

Author

Commented:
ok done
Top Expert 2010

Commented:
I'll put the code together and post as soon as I can.  It'll be tonight at the earliest.

Author

Commented:
Thank you very much for your help
I was wondering if we are allowed to give an email  address
It will be great if you can send me the program in a zip file to my address, in this way I will avoid loads of bugs
Top Expert 2010

Commented:
You're welcome.

Exchange email addresses is okay, but we need to work on the question here in public where other members can participate and future viewers can see exactly how we worked out the solution.  

The solution isn't a program, it's an Outlook macro.  The code is below.  Follow these instructions to add the code to Outlook.

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects
4.  If not already expanded, expand Modules
5.  Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
6.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
7.  Edit the code as needed.  I included comments wherever something needs to or can change
8.  Click the diskette icon on the toolbar to save the changes
9.  Close the VB Editor

To use the macro

1.  Open an Outlook folder.
2.  Select the messages you want to export headers for.  If you want to export the header of every message in the folder, then use CTRL+A to select them all.
3.  Run the macro ExportInternetHeaders.
4.  Outlook security will warn you that a program is trying to access your mailbox and ask for your permission to allow it to continue.  Give it permission.

The macro will export the header of each message selected to a separate file.  The file name will be the message subject minus any characters that aren't allowed in a file name.
Sub ExportInternetHeaders()
    ' Declare constants'
    Const CdoPR_TRANSPORT_MESSAGE_HEADERS = &H7D001E
    ' Edit the path on the next line'
    Const FILE_PATH = "C:\eeTesting\"
    ' Declare variables'
    Dim olkMsg As Object, _
        cdoSession As Object, _
        cdoMessage As Object, _
        cdoFields As Object, _
        objFSO As Object, _
        objFile As Object, _
        strHeader As String
    ' Initalize error handling'
    On Error Resume Next
    ' Initialize variables'
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    Set cdoSession = CreateObject("mapi.session")
    cdoSession.Logon , , False, False, 0 ' Use the existing Outlook session
    For Each olkMsg In Application.ActiveExplorer.Selection
        ' Get selected Message ID'
        Set cdoMessage = cdoSession.GetMessage(olkMsg.EntryID, olkMsg.Parent.StoreID)
        ' Get message fields'
        Set cdoFields = cdoMessage.Fields
        ' Get the header'
        strHeader = cdoFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Value
        ' Write the header to a text file'
        Set objFile = objFSO.CreateTextFile(FILE_PATH & RemoveIllegalCharacters(olkMsg.Subject) & ".txt")
        objFile.Write strHeader
        objFile.Close
    Next
    ' Logoff from CDO 1.21 sesison
    cdoSession.Logoff
    ' Tidy up
    Set objFSO = Nothing
    Set objFile = Nothing
    Set olkMsg = Nothing
    Set cdoSession = Nothing
    Set cdoMessage = Nothing
    Set cdoFields = Nothing
    On Error GoTo 0
    MsgBox "Header export complete.", vbInformation+vbOkOnly, "Export Headers"
End Sub

Function RemoveIllegalCharacters(strValue As String) As String
    ' Purpose: Remove characters that cannot be in a filename from a string.'
    ' Written: 4/24/2009'
    ' Author:  BlueDevilFan'
    ' Outlook: All versions'
    RemoveIllegalCharacters = strValue
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "<", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, ">", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, ":", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, Chr(34), "'")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "/", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "\", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "|", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "?", "")
    RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "*", "")
End Function

Open in new window

Author

Commented:
Hi
I tried your code seems working but I can’t find the exported file
Based on the code I thought it will go to  -Const FILE_PATH = "C:\eeTesting\"-
Is that right ...
Thanks for your help

Author

Commented:
Sorry I created the folder eetesting and it export the title of the emails but there are no headers inside  
The information that I’m looking for is what’s in the header, when you do message options you get :
Microsoft Mail Internet Headers Version 2.0
Received: from xxxxxxxxxxxxxxxxx ([10.111.2.111]) by xxxxxxx.com with Microsoft SMTPSVC
       Wed, 16 Jun 2010 09:34:02 +0100
Received: from mail1.xxxx.com ([193.111.255.00]) by xxxxx.com over TLS secured channel with Microsoft SMTPSVC
       Wed, 16 Jun 2010 09:34:01 +0100
Return-Path: <xxxxxxx>
Received: from [111.109.255.3:22843] by server-xxxx.com; Wed, 16 Jun 2010 08:34:01 +0000
X-VirusChecked: Checked
X-Originating-IP: [194.111.00.00]
Top Expert 2010

Commented:
Notice the comment above that command that says "Edit the path on the next line".  Change the path to point to a folder that exists on your computer.
Top Expert 2010

Commented:
That is the header.

Author

Commented:
Am confused you mean the title of the email is the header, sorry about this
But what I need if possible is the information that we get from message option where it mention the IP of the sender  
many thx
Top Expert 2010

Commented:
I didn't say the title of the email is the header.  I said that the message subject is the file name of the file containing the exported header.  You posted a header.  I thought you were saying that the exported file contained that information and that in your opinion that wasn't the header.  Maybe I misunderstood.  Are you saying that the exported files, one for each message, don't contain anything?  They are blank?

Author

Commented:
yes they are, it export only the the subject but no headers inside the text file, blank inside
Top Expert 2010

Commented:
I tested the code before posting, so I know it works.  Remove line 15 of the code and try again.  Let me know if you get an error.

Author

Commented:
can you copy paste line 15 here please
Top Expert 2010

Commented:
Why do I need to post line 15?  All you have to do is look back at the post with the code and find the line numbered 15.  this is line 15:

    On Error Resume Next

Author

Commented:
I wasnt sure line 15 was as when I did remove it I get a bug on
 Set cdoSession = CreateObject("mapi.session")
Top Expert 2010

Commented:
That means there's a problem with CDO.  What was the exact error?

Author

Commented:
I tried and tried and tried tu turn arround the code ...
when I desactivate line 15 I get

 Run time error 429  activex component can't creat object

please help
Top Expert 2010

Commented:
Then CDO isn't installed, isn't installed properly, or something on your computer is preventing it from being used.  

Author

Commented:
I wil try from a diffrent computer tonight and will let you know

sorry and thank you for your help
Top Expert 2010

Commented:
Ok.  No problem.

Author

Commented:
Its working thnak you very very much :)
sorry about beeing silly ...
Top Expert 2010
Commented:
That's great.  You're welcome.  No need to apologize, I didn't think you were being silly.  

Author

Commented:
Very helpful