Convert an EML File to PDF in C/C++

Cloudmersive
2 min readJul 21, 2021

--

Since EML files were designed by Microsoft, they generally work best for individuals with Outlook email accounts. If you are sharing an EML file with a partner or client who doesn’t utilize Outlook, the message you are attempting to convey may not translate properly. To ensure you are providing the smoothest experience, we are going to demonstrate an API solution that can be used in C/C++ to convert an EML file to the display-friendly PDF format.

We will begin by Installing libcurl in our C/C++ project:

libcurl/7.75.0

After the installation is complete, we can input the target EML file and call the 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/pdf");
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, "bodyOnly: <boolean>");
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);

This process is easy to use and supports images that are base 64 inline. To retrieve your API key, visit the Cloudmersive website to register for a free account; this provides 800 calls/month across our entire library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet