PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Email
li_Success = 0
// 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.
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
// Load an HTML email that contains related images.
li_Success = loo_Email.LoadEml("qa_data/eml/html_with_images.eml")
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
// Use relative paths in the unpacked HTML.
loo_Email.UnpackUseRelPaths = 1
// Unpack the HTML body and its related files to the filesystem.
// Arguments: unpackDir, htmlFilename, partsSubdir.
li_Success = loo_Email.UnpackHtml("qa_output/unpacked","message.html","parts")
if li_Success = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Email
return
end if
Write-Debug "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.
destroy loo_Email