Sample code for 30+ languages & platforms
DataFlex

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached message).

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Integer iNumAttached
    Variant vEmail2
    Handle hoEmail2
    String sTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    // Load an email from a .eml
    Get ComLoadEml Of hoEmail "embeddedEmail.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Display how many attached emails are embedded within
    // this one:
    Get ComNumAttachedMessages Of hoEmail To iNumAttached
    Showln "numAttached = " iNumAttached

    // Get the 1st attached message.
    Get Create (RefClass(cComChilkatEmail)) To hoEmail2
    If (Not(IsComObjectCreated(hoEmail2))) Begin
        Send CreateComObject of hoEmail2
    End
    Get pvComObject of hoEmail2 to vEmail2
    Get ComGetAttachedEmail Of hoEmail 0 vEmail2 To iSuccess
    If (iSuccess = True) Begin

        // Display the subject, From, and a header field...
        Get ComSubject Of hoEmail2 To sTemp1
        Showln sTemp1
        Get ComFrom Of hoEmail2 To sTemp1
        Showln sTemp1
        Get ComGetHeaderField Of hoEmail2 "X-SOMETHING" To sTemp1
        Showln sTemp1
    End



End_Procedure