Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Get Email HTML Body with Images as Base64 Inline Data

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Variant vSbHtml
    Handle hoSbHtml
    Boolean iInlineImageData
    String sHtmlStr
    String sTemp1

    // ---------------------------------------------------------------------------------------------------------------------------------
    // 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.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Get ComLoadEml Of hoEmail "qa_data/eml/sample.eml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHtml
    If (Not(IsComObjectCreated(hoSbHtml))) Begin
        Send CreateComObject of hoSbHtml
    End
    Move True To iInlineImageData
    Get pvComObject of hoSbHtml to vSbHtml
    Get ComGetHtmlBodySb Of hoEmail iInlineImageData vSbHtml To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // The HTML with inlined base64 image data is now contained in the StringBuilder.
    Get ComGetAsString Of hoSbHtml To sHtmlStr

    Get ComWriteFile Of hoSbHtml "c:/temp/qa_output/sample.html" "utf-8" False To iSuccess

    Showln "Success."


End_Procedure

 

© 2000-2025 Chilkat Software, Inc. All Rights Reserved.