Sample code for 30+ languages & platforms
DataFlex

Set an Email Body with a Content-Type

See more Email Object Examples

Demonstrates the Chilkat Email.SetTextBody method, which sets the body of the email and also sets the Content-Type header field to the value in the second argument (a textual MIME type such as text/plain or text/html). If the email is already multipart/alternative, an alternative with the given content type is added, or replaced if one already exists. This example sets a plain-text body.

Background: SetTextBody is the general body-setter where you name the MIME type, making it flexible for building multipart/alternative messages one representation at a time. When your goal is specifically a plain-text/HTML pair, the dedicated methods — SetHtmlBody with AddPlainTextAlternativeBody, or AddHtmlAlternativeBody — express the intended alternative structure more clearly.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    String sTemp1
    Boolean bTemp1

    //  Demonstrates the SetTextBody method, which sets the body of the email and also sets the
    //  Content-Type header field to the value in the second argument (a textual MIME type such
    //  as text/plain or text/html).  If the email is already multipart/alternative, an
    //  alternative with the given Content-Type is added (or replaced if one already exists).

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "SetTextBody example"

    //  Set a plain-text body with Content-Type text/plain.
    Send ComSetTextBody To hoEmail "This is the plain-text body of the message." "text/plain"

    Get ComHasPlainTextBody Of hoEmail To bTemp1
    Showln "HasPlainTextBody: " bTemp1
    Get ComGetMime Of hoEmail To sTemp1
    Showln sTemp1


End_Procedure