Sample code for 30+ languages & platforms
PowerBuilder

Get an Alternative Body into a BinData

See more Email Object Examples

Demonstrates the Chilkat Email.GetAlternativeBodyBd method, which copies the contents of the Nth alternative body into a BinData object. The first alternative body is at index 0, and it should only be called when NumAlternatives is greater than 0. This example builds a message with plain-text and HTML alternatives and copies the first into a BinData.

Background: This is the binary counterpart to GetAlternativeBody (which returns text). Reading an alternative into a BinData preserves the exact bytes — important when a body part uses a binary or unusual transfer encoding, or when you intend to hash it or write it out verbatim rather than decode it to a string.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Bd

li_Success = 0

//  Demonstrates the GetAlternativeBodyBd method, which copies the contents of the Nth
//  alternative body into a BinData object.  The first alternative body is at index 0; call
//  only when NumAlternatives is greater than 0.

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 = "GetAlternativeBodyBd example"

loo_Email.SetTextBody("This is the plain-text alternative.","text/plain")
loo_Email.AddHtmlAlternativeBody("<html><body>This is the HTML alternative.</body></html>")

//  Copy the first alternative body (index 0) into a BinData object.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Email.GetAlternativeBodyBd(0,loo_Bd)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Bd
    return
end if

Write-Debug "Alternative 0 size (bytes) = " + string(loo_Bd.NumBytes)


destroy loo_Email
destroy loo_Bd