Read Message Headers

May 11 2006 2:07 PM


I'm trying to read a message header in Outlook format (RFC2822).
also I supposed to download the entire message in a MemoryStream format, but I couldn't do that only using the interop.outlook

this is part of the code

' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application
' Get Mapi NameSpace.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("julioz", "zapata",
False, True) ' TODO:

' Get Messages collection of Inbox.
Dim oInbox As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)Dim oItems As Outlook.Items = oInbox.Items
Console.WriteLine("Total : " & oItems.Count)
Dim sSearch As String
' Get unread e-mail messages.
sSearch = "[Unread] = True"
oItems = oItems.Restrict("[Unread] = True")
'Console.WriteLine("Total Unread : " & oItems.Count)

' Loop each unread message.
Dim oMsg As Outlook.ReportItem
'Memory stream declarations
Dim objItem As Integer
Dim s As Char()
Dim str As String
Dim i As Integer
Dim ms As New MemoryStream
'__________________________

For objItem = 1 To oItems.Count
oMsg = oItems.Item(objItem)
If oMsg.UnRead = True Then
Console.WriteLine(objItem)
Console.WriteLine(oMsg.Subject)
Console.WriteLine(oMsg.Body)
Console.WriteLine(oMsg.MessageClass)
Console.WriteLine(oMsg.EntryID)
Console.WriteLine(oMsg.ItemProperties)
Console.WriteLine("---------------------------")

'Converting message to Memory stream
'___________________________________

str = oMsg.Subject & oMsg.EntryID & oMsg.Body
s = str.ToCharArray
Dim b(s.Length - 1) As Byte
For i = 0 To s.Length - 1
b(i) = Convert.ToByte(s(i))
Next

ms.Write(b, 0, s.Length)
'___________________________________

bs.Process(ms)
'oMsg.UnRead = False

End If
Next

' Log off.
oNS.Logoff()
' Clean up.

oApp = Nothing
oNS = Nothing
oItems = Nothing
oMsg = Nothing

I'll apreciate any help