Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoWrapper
    Variant vNested
    Handle hoNested
    Integer i
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatEmail)) To hoWrapper
    If (Not(IsComObjectCreated(hoWrapper))) Begin
        Send CreateComObject of hoWrapper
    End
    Get ComLoadEml Of hoWrapper "forward-as-attachment.eml" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoWrapper To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSubject Of hoWrapper To sTemp1
    Showln "Cover note: " sTemp1
    Get ComNumAttachedMessages Of hoWrapper To iTemp1
    If (iTemp1 = 0) Begin
        Showln "No attached messages."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatEmail)) To hoNested
    If (Not(IsComObjectCreated(hoNested))) Begin
        Send CreateComObject of hoNested
    End
    Move 0 To i
    While (i < (ComNumAttachedMessages(hoWrapper)))
        Get pvComObject of hoNested to vNested
        Get ComGetAttachedEmail Of hoWrapper i vNested To iSuccess
        If (iSuccess <> True) Begin
            Get ComLastErrorText Of hoWrapper To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Get ComFrom Of hoNested To sTemp1
        Showln "Original author: " sTemp1
        Get ComSubject Of hoNested To sTemp1
        Showln "Original subject: " sTemp1
        Get ComNumAttachments Of hoNested To iTemp1
        Showln "Files on the original: " iTemp1
        Move (i + 1) To i
    Loop



End_Procedure