Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmailW email;
success = FALSE;
// 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.
email = CkEmailW_Create();
// Load an HTML email that contains related images.
success = CkEmailW_LoadEml(email,L"qa_data/eml/html_with_images.eml");
if (success == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(email);
return true;
}
// Use relative paths in the unpacked HTML.
CkEmailW_putUnpackUseRelPaths(email,TRUE);
// Unpack the HTML body and its related files to the filesystem.
// Arguments: unpackDir, htmlFilename, partsSubdir.
success = CkEmailW_UnpackHtml(email,L"qa_output/unpacked",L"message.html",L"parts");
if (success == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(email);
return true;
}
wprintf(L"Unpacked the HTML email using relative paths.\n");
// Note: Paths such as "qa_data/..." and "qa_output/..." are relative local
// filesystem paths, relative to the current working directory of the running application.
CkEmailW_Dispose(email);
}