CDO.Message and iBodyPart

CDO.Message and iBodyPart

Post by Kjell Arne Hauglan » Wed, 03 Jul 2002 06:23:56


How can  I turn a iBodyPart of type message/rfc822 into a new CDO.Message?
Is that the right method or am I already lost?

I need to loop through an incoming message's attachments (attached messages)
and get the sender addresses of those messages.


This is what I've done:

Private Sub IExStoreAsyncEvents_OnSave(ByVal pEventInfo As
Exoledb.IExStoreEventInfo, ByVal bstrURLItem As String, ByVal lFlags As
    On Error Resume Next

    Dim DispEvtInfo As IExStoreDispEventInfo
    Dim ADODBRec    As ADODB.Record
    Dim objField As ADODB.Field
    Dim objMessage As New CDO.Message
    Dim objAttachment As CDO.IBodyPart
    Set DispEvtInfo = pEventInfo

'Small sample that shows how to use ADO Record Object and Fields inside
    Set ADODBRec = DispEvtInfo.EventRecord

    Log "Event info:" & vbCrLf

    For Each objField In ADODBRec.Fields
        Log "Field: " & objField.Name & " - Value: " & objField.Value &

    If lFlags And EVT_IS_DELIVERED Then
        Log "Newly arrived element." & vbCrLf

    End If
    'Log ("  DAV:Displayname Value: " &
ADODBRec.Fields("DAV:displayname").Value) & vbCrLf

    If (lFlags And EVT_NEW_ITEM) = EVT_NEW_ITEM And (lFlags And
        'ny mail ankommet
        Log "IExStoreAsyncEvents_OnSave: " & bstrURLItem & vbCrLf
        Log "IExStoreAsyncEvents_OnSave: New Folder, " & bstrURLItem &
    End If

    objMessage.DataSource.Open bstrURLItem

    Log objMessage.Subject & vbCrLf
    For Each objAttachment In objMessage.Attachments
        For Each objField In objAttachment.Fields
            If InStr(1, objField.Value, "message/rfc822") Then
                '*** WHAT TO DO HERE?
            End If
            Log "Field: " & objField.Name & " - Value: " & objField.Value &
        Log "---" & vbCrLf
End Sub


kjell arne


1. Is IBodyPart.SaveToFile Asynchronous?

I would like to extract an attachment from a message in an Exchange Folder
and then open the extracted file for modification.  I am using the following
VB code:

    Dim iAttachement as CDO.IBodyPart
    Dim oMessage as CDO.Message

    'Open Connection here (objConn)

    Set oMessage = CreateObject("CDO.Message")
    oMessage.DataSource.Open strMessageURL, objConn

    For Each iAttachment In oMessage.Attachments

        'Save the Attachment to the Temp file
        iAttachment.SaveToFile strTempDocURL

        With CreateObject("ADODB.Record")

            'Open the Temp File
            .Open strTempDocURL, objConn, 3

            'Put code here to modifiy the item

            'Save it

        End With

This fails on the .Open line of the Record object with the error "Object or
data matching the name, range, or selection criteria was not found within
the scope of this operation."  However, if I run this in debug mode, and
allow for some time between the SaveToFile and Open lines, there are no
errors.  Is the SaveToFile method asynchronous?  If so, how can I ensure
that the Save is completed before the Open?


2. Test Data for Exchange

3. Getting a CDO 1.21 Message object from a CDO for Exchange 2000 Message object...

4. Using a VB program to allow server operators to create Exchange ID

5. CDO Message ID Problem

6. Outlook Web Access

7. CDO, read message from a file

8. Possible Mail Loop

9. CDO - Forwarding messages with attachments

10. Sending messages using CDO

11. Filtering a Message Collection with CDO

12. CDO & Message.Text Throwing Run-Time Error

13. CDO Messages "GetNext"