Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oEmail

nSuccess := 0

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

oEmail := CreateObject("Chilkat.Email")
oEmail:FromName := "Sam Lee"
oEmail:FromAddress := "sam@example.com"
oEmail:ReplyTo := "replies@example.com"
nSuccess := oEmail:AddTo("Alex Rivera", "alex@example.net")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

oEmail:Subject := "Sample message"
oEmail:Charset := "utf-8"
//  A custom header can carry a reference alongside the standard message fields.
oEmail:AddHeaderField("X-Reference-ID", "REF-42")
nSuccess := oEmail:AddPlainTextAlternativeBody("Read more at https://example.com/details.")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

nSuccess := oEmail:AddHtmlAlternativeBody("<p><a href='https://example.com/details'>Read more</a></p>")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

nSuccess := oEmail:SaveEml("text-and-html.eml")
IF (nSuccess != 1)
    ? oEmail:LastErrorText
    oEmail:destroy()
    RETURN
ENDIF

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

oEmail:destroy()