Sample code for 30+ languages & platforms
DataFlex

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    Variant vSb
    Handle hoSb
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
    //  it to a StringBuilder.  The only argument is the StringBuilder.

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

    Get ComSetBodyFromPlainText Of hoMime "Hello, this is the message body." To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Append the serialized MIME to a StringBuilder.  Existing content is preserved.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Get pvComObject of hoSb to vSb
    Get ComGetMimeSb Of hoMime vSb To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComGetAsString Of hoSb To sTemp1
    Showln sTemp1


End_Procedure