Sample code for 30+ languages & platforms
PowerBuilder

Add an HTML Alternative Body to an Email

See more Email Object Examples

Demonstrates the Chilkat Email.AddHtmlAlternativeBody method, which adds an HTML alternative body. Combined with a plain-text body, it produces a multipart/alternative email that offers both representations of the same content. This example sets a plain-text body, adds an HTML alternative, and prints the resulting alternative count.

Background: A well-formed HTML email usually ships two versions of the body: a rich HTML version and a plain-text fallback, wrapped in a multipart/alternative container. The receiving client displays whichever it prefers — modern clients show the HTML, while text-only clients (or spam filters and accessibility tools) use the plain text. Providing both improves deliverability and ensures every recipient can read the message.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email

//  Demonstrates the AddHtmlAlternativeBody method, which adds an HTML alternative body to
//  the email.  Combined with a plain-text body, this produces a multipart/alternative
//  email that offers both representations.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Plain-text and HTML alternatives"

//  Start with a plain-text body.
loo_Email.SetTextBody("This is the plain-text version of the message.","text/plain")

//  Add an HTML alternative, creating a multipart/alternative email.
loo_Email.AddHtmlAlternativeBody("<html><body><b>This is the HTML version.</b></body></html>")

Write-Debug "NumAlternatives = " + string(loo_Email.NumAlternatives)


destroy loo_Email