Sample code for 30+ languages & platforms
DataFlex

Append a Part to a Multipart MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.AppendPart method, which appends a copy of another Mime as the last direct child. The only argument is the source Mime. Chilkat copies it, so later changes to the source do not affect the appended part.

Background: This is the general way to build up a multipart entity from parts you construct yourself — a text body, an HTML body, a nested multipart. Because it appends a copy, you can reuse and modify the source object afterward, or append it more than once, without surprises. For attaching a file directly, AppendPartFromFile is more convenient.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    Variant vPart
    Handle hoPart
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  Demonstrates the Mime.AppendPart method, which appends a copy of another Mime as the last direct
    //  child.  The only argument is the Mime to append.  Chilkat copies it, so later changes to the
    //  source do not affect the appended part.

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End
    Get ComNewMultipartMixed Of hoMime To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Build a part and append a copy of it.
    Get Create (RefClass(cComChilkatMime)) To hoPart
    If (Not(IsComObjectCreated(hoPart))) Begin
        Send CreateComObject of hoPart
    End
    Get ComSetBodyFromPlainText Of hoPart "This is an appended part." To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPart To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoPart to vPart
    Get ComAppendPart Of hoMime vPart To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumParts Of hoMime To iTemp1
    Showln "Number of parts: " iTemp1


End_Procedure