Sample code for 30+ languages & platforms
PowerBuilder

Set the Email Body from a BinData

See more Email Object Examples

Demonstrates the Chilkat Email.SetBodyBd method, which sets the main email body from the binary data in a BinData object. The second argument is the MIME Content-Type, the third is the disposition (may be empty, inline, or attachment), and the fourth is the filename. This example loads HTML content into a BinData and sets it as the body.

Background: SetBodyBd gives low-level control over the body when you already have its bytes and want to specify the exact Content-Type and MIME disposition yourself. It suits content that is generated or stored as binary — for example an EDI payload, a pre-rendered HTML fragment, or any custom content type — where the convenience of SetHtmlBody / SetTextBody does not apply.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Bd

li_Success = 0

//  Demonstrates the SetBodyBd method, which sets the main email body from the binary data in
//  a BinData object.  The second argument is the MIME Content-Type, the third is the
//  disposition (may be empty, "inline", or "attachment"), and the fourth is the filename.

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 = "Body from BinData"

//  Load the body content from a file into a BinData object.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Bd.LoadFile("qa_data/html/body.html")
if li_Success = 0 then
    Write-Debug loo_Bd.LastErrorText
    destroy loo_Email
    destroy loo_Bd
    return
end if

//  Set the main body from the binary data as text/html.
li_Success = loo_Email.SetBodyBd(loo_Bd,"text/html","","")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Bd
    return
end if

Write-Debug "HasHtmlBody: " + string(loo_Email.HasHtmlBody())

//  Note: The path "qa_data/html/body.html" is a relative local filesystem path,
//  relative to the current working directory of the running application.


destroy loo_Email
destroy loo_Bd