Sample code for 30+ languages & platforms
PowerBuilder

Get and Set the Email Body

See more Email Object Examples

Demonstrates the Chilkat Email.Body property. When you set Body, Chilkat inspects the content and decides whether it should be treated as HTML or plain-text. When you read Body, an email that contains both plain-text and HTML alternatives returns the HTML body — use GetHtmlBody or GetPlainTextBody to retrieve a specific representation. This example sets a plain-text body and reads it back.

Background: A single email often carries two versions of the same message — a plain-text body and an HTML body — bundled together in a multipart/alternative MIME structure. The receiving mail client picks whichever version it prefers to display. Because of this, "the body" is ambiguous: the Body property favors the HTML version when both are present, which is why Chilkat also provides GetHtmlBody, GetPlainTextBody, HasHtmlBody, and HasPlainTextBody for precise control.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email
string ls_BodyText

//  Demonstrates getting and setting the Email.Body property.
//  When setting Body, Chilkat inspects the content to decide whether it is
//  HTML or plain-text.  When reading, an email that has both plain-text and
//  HTML alternatives returns the HTML body.

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

//  Set the body.
loo_Email.Body = "This is the plain-text body of the email."

//  Read the Body property back.
ls_BodyText = loo_Email.Body
Write-Debug "Body = " + ls_BodyText


destroy loo_Email