DataFlex
DataFlex
Use Relative Paths When Unpacking HTML Email
See more Email Object Examples
Demonstrates the Chilkat Email.UnpackUseRelPaths property, which applies to the UnpackHtml method. When true (the default), the unpacked HTML uses relative paths for links to the related files (images and style sheets) written to disk; when false, absolute paths are used. This example loads an HTML email and unpacks it using relative paths.
Background: "Unpacking" an HTML email means writing its HTML body to a file and its inline images/stylesheets to a subfolder, then rewriting the
cid: references so the saved HTML displays correctly in a browser. Relative paths (like parts/logo.png) keep the folder self-contained and portable — you can move or deploy the whole directory and the links still work. Absolute paths point at one fixed location, which is fine for immediate local viewing but breaks if the files move.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
String sTemp1
Move False To iSuccess
// Demonstrates the Email.UnpackUseRelPaths property, which applies to the UnpackHtml
// method. When true (the default), the unpacked HTML uses relative paths for its links
// to the related files (images, style sheets). When false, absolute paths are used.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
// Load an HTML email that contains related images.
Get ComLoadEml Of hoEmail "qa_data/eml/html_with_images.eml" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
// Use relative paths in the unpacked HTML.
Set ComUnpackUseRelPaths Of hoEmail To True
// Unpack the HTML body and its related files to the filesystem.
// Arguments: unpackDir, htmlFilename, partsSubdir.
Get ComUnpackHtml Of hoEmail "qa_output/unpacked" "message.html" "parts" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Unpacked the HTML email using relative paths."
// Note: Paths such as "qa_data/..." and "qa_output/..." are relative local
// filesystem paths, relative to the current working directory of the running application.
End_Procedure