PureBasic Requires Chilkat v11.0.0+
PureBasic
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 PureBasic Downloads
IncludeFile "CkEmail.pb"
Procedure ChilkatExample()
success.i = 0
; Assumes Chilkat is unlocked. See Global Unlock Sample.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkFrom(email, "Workshop team <events@example.com>")
success = CkEmail::ckAddTo(email,"Alex Rivera","alex@example.net")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Workshop registration")
CkEmail::ckSetHtmlBody(email,"<html><body><p>Registration confirmed.</p><img src=" + Chr(34) + "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" + Chr(34) + " alt=" + Chr(34) + "Mark" + Chr(34) + "></body></html>")
success = CkEmail::ckConvertInlineImages(email)
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Related images: " + Str(CkEmail::ckNumRelatedItems(email))
Debug CkEmail::ckGetHtmlBody(email)
success = CkEmail::ckSaveEml(email,"related-images.eml")
If success <> 1
Debug CkEmail::ckLastErrorText(email)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Saved related-images.eml."
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure