CDO.Message and iBodyPart

CDO.Message and iBodyPart

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



Hi

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.

ADO or CDO?

This is what I've done:

Private Sub IExStoreAsyncEvents_OnSave(ByVal pEventInfo As
Exoledb.IExStoreEventInfo, ByVal bstrURLItem As String, ByVal lFlags As
Long)
    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
events
    Set ADODBRec = DispEvtInfo.EventRecord

    Log "Event info:" & vbCrLf

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

    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
EVT_IS_COLLECTION) <> EVT_IS_COLLECTION Then
        'ny mail ankommet
        Log "IExStoreAsyncEvents_OnSave: " & bstrURLItem & vbCrLf
    Else
        Log "IExStoreAsyncEvents_OnSave: New Folder, " & bstrURLItem &
vbCrLf
    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 &
vbCrLf
        Next
        Log "---" & vbCrLf
    Next
End Sub

Thanks!

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
            .Fields.Update

        End With
    Next

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?

Thanks,
Kevin

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"