Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Get Email HTML Body with Images as Base64 Inline DataDemonstrates how to get the email's HTML body with referenced MIME parts (i.e. related images) embedded in the HTML as base64 data. Note: This example requires Chilkat v10.1.2 or later.
integer li_rc oleobject loo_Email integer li_Success oleobject loo_SbHtml integer li_InlineImageData string ls_HtmlStr // --------------------------------------------------------------------------------------------------------------------------------- // Prerequisite Knowledge: // In HTML emails, CID (Content-ID) image references allow embedding images directly into the email as part of the message body, // instead of linking to external images. // * Each embedded image is assigned a unique Content-ID (CID) in the email�s MIME structure. // * The CID is a unique identifier, such as image001@domain.com. // For example: <img src="cid:image001@domain.com" alt="Embedded Image"> // --------------------------------------------------------------------------------------------------------------------------------- // However, in HTML, you can embed image data directly into an <img> tag by using Base64 encoding. // This method eliminates the need for external image files by encoding the image as a string and including it within the HTML. // For example: // <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA .... RU5ErkJggg==" alt="Embedded Image"> // Chilkat added the GetHtmlBodySb method in version 10.1.2 which provides an option for gathering the // image data from the mulitpart/related MIME parts of the email, and replaces the "cid" img references with // the base64 data. loo_Email = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 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 li_Success = loo_Email.LoadEml("qa_data/eml/sample.eml") if li_Success = 0 then Write-Debug loo_Email.LastErrorText destroy loo_Email return end if loo_SbHtml = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbHtml.ConnectToNewObject("Chilkat.StringBuilder") li_InlineImageData = 1 li_Success = loo_Email.GetHtmlBodySb(li_InlineImageData,loo_SbHtml) if li_Success = 0 then Write-Debug loo_Email.LastErrorText destroy loo_Email destroy loo_SbHtml return end if // The HTML with inlined base64 image data is now contained in the StringBuilder. ls_HtmlStr = loo_SbHtml.GetAsString() loo_SbHtml.WriteFile("c:/temp/qa_output/sample.html","utf-8",0) Write-Debug "Success." destroy loo_Email destroy loo_SbHtml |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.