Sample code for 30+ languages & platforms
DataFlex Requires Chilkat v11.0.0+

Convert image data URLs to related MIME parts

See more Email Object Examples

Start with HTML that contains image bytes in a data URL. Convert it to conventional CID references and inspect the resulting related-item count before saving.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoEmail
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComFrom Of hoEmail To "Workshop team <events@example.com>"
    Get ComAddTo Of hoEmail "Alex Rivera" "alex@example.net" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Set ComSubject Of hoEmail To "Workshop registration"
    Send ComSetHtmlBody To hoEmail '<html><body><p>Registration confirmed.</p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" alt="Mark"></body></html>'
    Get ComConvertInlineImages Of hoEmail To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumRelatedItems Of hoEmail To iTemp1
    Showln "Related images: " iTemp1
    Get ComGetHtmlBody Of hoEmail To sTemp1
    Showln sTemp1

    Get ComSaveEml Of hoEmail "related-images.eml" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoEmail To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Saved related-images.eml."


End_Procedure