Convert an Outlook EML File to PNG in C/C++
Employing thumbnail images on your website or application is a great way to conserve space while encouraging user engagement. However, creating images from non-image files, such as EML, can be a complicated and time-consuming project. To avoid the whole parse, render, and rasterize debacle you would have to go through, we are going to provide a brief tutorial on how you can automatically convert EML files to an array of PNG images; this will save you from the potential headache the manual process could generate.
We will start things off by installing libcurl:
libcurl/7.75.0
Then, we can call the conversion function with the following code:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/eml/to/png");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);
To retrieve an API key, simply visit the Cloudmersive website to register for a free account; this provides 800 monthly calls across our multitude of APIs.