PureBasic
PureBasic
Add a Related Item from BinData by Content-Location
See more Email Object Examples
Demonstrates the Chilkat Email.AddRelatedBd2 method, which adds a related item using the binary data in a BinData object, addressed by Content-Location. The second argument specifies the filename, path, or URL used by the corresponding HTML reference. This example embeds an image referenced as logo.png.
Background: This is the binary counterpart of
AddRelatedString2 and the Content-Location sibling of AddRelatedBd. Instead of a generated cid: reference, the HTML keeps an ordinary src="logo.png" and the related part is matched to it by name — convenient when turning an existing web page into an email so its original relative URLs keep working.Chilkat PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the AddRelatedBd2 method, which adds a related item using the binary data in
; a BinData object, addressed by Content-Location. The second argument specifies the filename/path/URL
; used by the corresponding HTML reference.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Related image from BinData (Content-Location)")
; The HTML references the image by the same name used as the Content-Location.
CkEmail::ckSetHtmlBody(email,"<html><body><img src=" + Chr(34) + "logo.png" + Chr(34) + "/></body></html>")
; Load the image data from a file into a BinData object.
bdImage.i = CkBinData::ckCreate()
If bdImage.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkBinData::ckLoadFile(bdImage,"qa_data/images/logo.png")
If success = 0
Debug CkBinData::ckLastErrorText(bdImage)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdImage)
ProcedureReturn
EndIf
; Add the image as a related item addressed by Content-Location "logo.png".
success = CkEmail::ckAddRelatedBd2(email,bdImage,"logo.png")
If success = 0
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdImage)
ProcedureReturn
EndIf
Debug "NumRelatedItems = " + Str(CkEmail::ckNumRelatedItems(email))
; Note: The path "qa_data/images/logo.png" is a relative local filesystem path,
; relative to the current working directory of the running application.
CkEmail::ckDispose(email)
CkBinData::ckDispose(bdImage)
ProcedureReturn
EndProcedure