PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_BdImage
li_Success = 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.
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 = "Related image from BinData (Content-Location)"
// The HTML references the image by the same name used as the Content-Location.
loo_Email.SetHtmlBody("<html><body><img src=~"logo.png~"/></body></html>")
// Load the image data from a file into a BinData object.
loo_BdImage = create oleobject
li_rc = loo_BdImage.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_BdImage.LoadFile("qa_data/images/logo.png")
if li_Success = 0 then
Write-Debug loo_BdImage.LastErrorText
destroy loo_Email
destroy loo_BdImage
return
end if
// Add the image as a related item addressed by Content-Location "logo.png".
li_Success = loo_Email.AddRelatedBd2(loo_BdImage,"logo.png")
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
destroy loo_BdImage
return
end if
Write-Debug "NumRelatedItems = " + string(loo_Email.NumRelatedItems)
// Note: The path "qa_data/images/logo.png" is a relative local filesystem path,
// relative to the current working directory of the running application.
destroy loo_Email
destroy loo_BdImage