C Requires Chilkat v11.0.0+
C
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 C Downloads
#include <C_CkEmail.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmail email;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email = CkEmail_Create();
CkEmail_putFrom(email,"Workshop team <events@example.com>");
success = CkEmail_AddTo(email,"Alex Rivera","alex@example.net");
if (success != TRUE) {
printf("%s\n",CkEmail_lastErrorText(email));
CkEmail_Dispose(email);
return;
}
CkEmail_putSubject(email,"Workshop registration");
CkEmail_SetHtmlBody(email,"<html><body><p>Registration confirmed.</p><img src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\" alt=\"Mark\"></body></html>");
success = CkEmail_ConvertInlineImages(email);
if (success != TRUE) {
printf("%s\n",CkEmail_lastErrorText(email));
CkEmail_Dispose(email);
return;
}
printf("Related images: %d\n",CkEmail_getNumRelatedItems(email));
printf("%s\n",CkEmail_getHtmlBody(email));
success = CkEmail_SaveEml(email,"related-images.eml");
if (success != TRUE) {
printf("%s\n",CkEmail_lastErrorText(email));
CkEmail_Dispose(email);
return;
}
printf("Saved related-images.eml.\n");
CkEmail_Dispose(email);
}