Sample code for 30+ languages & platforms
DataFlex

Set a MIME Body from HTML

See more MIME Examples

Demonstrates the Chilkat Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media type to text/html. The only argument is the HTML text.

Background: Setting an HTML body is how you produce the rich-formatted part of a message. Chilkat marks it text/html and chooses the encoding based on the content — 7bit for ASCII, a charset-aware encoding otherwise. In practice an HTML email is usually paired with a plain-text alternative inside a multipart/alternative so clients that cannot render HTML still have readable text.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    String sHtml
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media
    //  type to text/html.  The only argument is the HTML text.

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

    Move "<html><body><h1>Hello</h1><p>This is an HTML body.</p></body></html>" To sHtml
    Get ComSetBodyFromHtml Of hoMime sHtml To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComContentType Of hoMime To sTemp1
    Showln "Content-Type: " sTemp1


End_Procedure