DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vBdImage
Handle hoBdImage
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Related image from BinData (Content-Location)"
// The HTML references the image by the same name used as the Content-Location.
Send ComSetHtmlBody To hoEmail '<html><body><img src="logo.png"/></body></html>'
// Load the image data from a file into a BinData object.
Get Create (RefClass(cComChilkatBinData)) To hoBdImage
If (Not(IsComObjectCreated(hoBdImage))) Begin
Send CreateComObject of hoBdImage
End
Get ComLoadFile Of hoBdImage "qa_data/images/logo.png" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoBdImage To sTemp1
Showln sTemp1
Procedure_Return
End
// Add the image as a related item addressed by Content-Location "logo.png".
Get pvComObject of hoBdImage to vBdImage
Get ComAddRelatedBd2 Of hoEmail vBdImage "logo.png" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComNumRelatedItems Of hoEmail To iTemp1
Showln "NumRelatedItems = " iTemp1
// Note: The path "qa_data/images/logo.png" is a relative local filesystem path,
// relative to the current working directory of the running application.
End_Procedure