DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
String sBodyText
// 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.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
// Set the body.
Set ComBody Of hoEmail To "This is the plain-text body of the email."
// Read the Body property back.
Get ComBody Of hoEmail To sBodyText
Showln "Body = " sBodyText
End_Procedure