Visual Basic 6.0
Visual Basic 6.0
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 Visual Basic 6.0 Downloads
Dim success As Long
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.
Dim email As New ChilkatEmail
' Load an HTML email that contains related images.
success = email.LoadEml("qa_data/eml/html_with_images.eml")
If (success = 0) Then
Debug.Print email.LastErrorText
Exit Sub
End If
' Use relative paths in the unpacked HTML.
email.UnpackUseRelPaths = 1
' Unpack the HTML body and its related files to the filesystem.
' Arguments: unpackDir, htmlFilename, partsSubdir.
success = email.UnpackHtml("qa_output/unpacked","message.html","parts")
If (success = 0) Then
Debug.Print email.LastErrorText
Exit Sub
End If
Debug.Print "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.