Skip to content

Instantly share code, notes, and snippets.

@umitanuki
Created May 31, 2010 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umitanuki/419930 to your computer and use it in GitHub Desktop.
Save umitanuki/419930 to your computer and use it in GitHub Desktop.
extract mail information from outlook
Const olFolderInbox = 6
Const ForWriting = 2
Const MessageID = 1709179138
Const PR_INTERNET_MESSAGE_ID = &H1035001E
Set fs = WScript.CreateObject("Scripting.FileSystemObject")
Set ofile = fs.OpenTextFile("c:\tmp\mail.tsv", ForWriting)
Set ol = WScript.CreateObject("Outlook.Application")
Set myNameSpace = ol.GetNameSpace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myItems = myFolder.Items
'WScript.echo myItems.Count
'Dim mapiSession As New MAPI.Session
'Dim mapiMessage As MAPI.Message
Set mapiSession = WScript.CreateObject("MAPI.Session")
mapiSession.Logon "", "", False, False, True
For a = 1 To myItems.Count Step 1
On Error Resume Next
Set item = myItems.Item(a)
' WScript.Echo item.Subject
Set mapiMessage = mapiSession.GetMessage(item.EntryID, item.Parent.StoreID)
' WScript.Echo mapiMessage.Fields(PR_INTERNET_MESSAGE_ID ).Value
ofile.Writeline item.Subject & chr(9) & item.ReceivedTime & chr(9) & item.SenderName & chr(9) & item.To & chr(9) & item.CC & chr(9) & item.BCC & chr(9) & item.senderEMailAddress & chr(9) & item.EntryID & chr(9) & mapiMessage.Fields(PR_INTERNET_MESSAGE_ID).Value
Next
ofile.Close
Set ol = Nothing
Set ofile = Nothing
Set fs = Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment