Sample code for 30+ languages & platforms
DataFlex

Load an Email from MIME in a StringBuilder

See more Email Object Examples

Demonstrates the Chilkat Email.SetFromMimeSb method, which loads an email from the MIME text stored in a StringBuilder object. On success, it replaces the entire current email. This example serializes one email into a StringBuilder with GetMimeSb, then reconstructs it in a second object.

Background: This is the StringBuilder counterpart to SetFromMimeText. When the MIME already lives in a StringBuilder — perhaps assembled or edited there — passing it directly avoids converting to an intermediate string, which is more efficient for large messages.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoSource
    Variant vSbMime
    Handle hoSbMime
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the SetFromMimeSb method, which loads an email from MIME text stored in a
    //  StringBuilder object.  On success, it replaces the entire current email.

    //  Build a source email and get its MIME into a StringBuilder.
    Get Create (RefClass(cComChilkatEmail)) To hoSource
    If (Not(IsComObjectCreated(hoSource))) Begin
        Send CreateComObject of hoSource
    End
    Set ComSubject Of hoSource To "Source message"
    Set ComFrom Of hoSource To "alice@example.com"
    Set ComBody Of hoSource To "Hello from a StringBuilder."
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbMime
    If (Not(IsComObjectCreated(hoSbMime))) Begin
        Send CreateComObject of hoSbMime
    End
    Get pvComObject of hoSbMime to vSbMime
    Get ComGetMimeSb Of hoSource vSbMime To iSuccess

    //  Load a new email object from the StringBuilder MIME.
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get pvComObject of hoSbMime to vSbMime
    Get ComSetFromMimeSb Of hoEmail vSbMime To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSubject Of hoEmail To sTemp1
    Showln "Loaded subject: " sTemp1


End_Procedure