Sample code for 30+ languages & platforms
DataFlex

Count the Report Parts in a multipart/report Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumReports property, which is the number of report parts in a multipart/report email. A part is counted as a report when its Content-Type is message/* (except message/rfc822) or text/rfc822-headers. Use GetReport to retrieve the body of each report part; indexes are zero-based. This example loads a report email and prints each report part.

Background: When a message can't be delivered, the mail system usually sends back a bounce known as a Delivery Status Notification (DSN). DSNs use the multipart/report structure, which bundles several parts: a human-readable explanation, a machine-readable message/delivery-status part describing exactly what happened (recipient, status code, failing server), and often the original message's headers. Reading these report parts lets a program automatically detect and process bounces.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    Integer n
    Integer i
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the read-only Email.NumReports property, which is the number of report
    //  parts in a multipart/report email (for example, a Delivery Status Notification).
    //  Use GetReport to retrieve the body of each report part.  Indexes are zero-based.

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

    //  Load a multipart/report email (such as a bounce / DSN message).
    Get ComLoadEml Of hoEmail "qa_data/eml/dsn_bounce.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumReports Of hoEmail To n
    Showln "NumReports = " n

    For i From 0 To (n - 1)
        Showln "---- Report " i " ----"
        Get ComGetReport Of hoEmail i To sTemp1
        Showln sTemp1
    Loop



End_Procedure