Sample code for 30+ languages & platforms
Unicode C++ 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 Unicode C++ Downloads

Unicode C++
#include <CkEmailW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkEmailW email;
    email.put_From(L"Workshop team <events@example.com>");
    success = email.AddTo(L"Alex Rivera",L"alex@example.net");
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    email.put_Subject(L"Workshop registration");
    email.SetHtmlBody(L"<html><body><p>Registration confirmed.</p><img src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\" alt=\"Mark\"></body></html>");
    success = email.ConvertInlineImages();
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    wprintf(L"Related images: %d\n",email.get_NumRelatedItems());
    wprintf(L"%s\n",email.getHtmlBody());

    success = email.SaveEml(L"related-images.eml");
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    wprintf(L"Saved related-images.eml.\n");
    }