Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Create an email with plain-text and HTML bodies

See more Email Object Examples

Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComFromName Of hoEmail To "Sam Lee"
    Set ComFromAddress Of hoEmail To "sam@example.com"
    Set ComReplyTo Of hoEmail To "replies@example.com"
    Get ComAddTo Of hoEmail "Alex Rivera" "alex@example.net" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComSubject Of hoEmail To "Sample message"
    Set ComCharset Of hoEmail To "utf-8"
    //  A custom header can carry a reference alongside the standard message fields.
    Send ComAddHeaderField To hoEmail "X-Reference-ID" "REF-42"
    Get ComAddPlainTextAlternativeBody Of hoEmail "Read more at https://example.com/details." To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddHtmlAlternativeBody Of hoEmail "<p><a href='https://example.com/details'>Read more</a></p>" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSaveEml Of hoEmail "text-and-html.eml" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Saved text-and-html.eml."


End_Procedure