How to convert a MIME string to a CDO.Message



I have a string containing a MIME encoded email and I need to convert it to
a CDO.Message object. I can currently convert it by saving it to a file,
then opening an ADO.Stream using LoadFromFile and then using the
CDO.Message.DataSource.OpenObject to load the stream. I would like to not
have to save it to a file. Here's the code I'm playing with but does not
work (the CDO.Message object is empty).

' buf contains the MIME encoded email string
Public Sub TestWithString(ByVal buf As String)

' now build the ADODB.Stream object
Dim so As New ADODB.Stream
so.Mode = ConnectModeEnum.adModeReadWrite
so.Type = StreamTypeEnum.adTypeText
so.Open()
' fill the stream with the text
so.WriteText(buf, StreamWriteEnum.adWriteLine)

' reset the position in the stream
so.Position = 0

' now build the CDO message
Dim msg As New CDO.Message
msg.DataSource.OpenObject(so, "_Stream")

' just to test it
Console.WriteLine(msg.From)
Console.WriteLine(msg.TextBody)

End Sub


.



Relevant Pages