PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 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.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Body from BinData")
; Load the body content from a file into a BinData object.
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkBinData::ckLoadFile(bd,"qa_data/html/body.html")
If success = 0
Debug CkBinData::ckLastErrorText(bd)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bd)
ProcedureReturn
EndIf
; Set the main body from the binary data as text/html.
success = CkEmail::ckSetBodyBd(email,bd,"text/html","","")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bd)
ProcedureReturn
EndIf
Debug "HasHtmlBody: " + Str(CkEmail::ckHasHtmlBody(email))
; Note: The path "qa_data/html/body.html" is a relative local filesystem path,
; relative to the current working directory of the running application.
CkEmail::ckDispose(email)
CkBinData::ckDispose(bd)
ProcedureReturn
EndProcedure