Sample code for 30+ languages & platforms
DataFlex

Create a multipart/related MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartRelated method, which initializes the object as an empty multipart/related entity. It takes no arguments; the primary part and its related resources are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/related ties a primary part to the resources it references — most commonly an HTML body and the inline images it embeds via cid: references. Unlike a plain attachment, a related image is displayed within the message rather than listed separately. The HTML part comes first, followed by each referenced resource with a matching Content-ID.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    Variant vHtmlPart
    Handle hoHtmlPart
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  Demonstrates the Mime.NewMultipartRelated method, which initializes the object as an empty
    //  multipart/related entity, clearing any existing content.  It takes no arguments.

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End

    Get ComNewMultipartRelated Of hoMime To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  multipart/related groups a primary part with the resources it references, such as an HTML body
    //  and the inline images it displays.
    Get Create (RefClass(cComChilkatMime)) To hoHtmlPart
    If (Not(IsComObjectCreated(hoHtmlPart))) Begin
        Send CreateComObject of hoHtmlPart
    End
    Get ComSetBodyFromHtml Of hoHtmlPart '<html><body><img src="cid:logo"></body></html>' To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHtmlPart To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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

    Get ComAppendPartFromFile Of hoMime "qa_data/logo.png" 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