How to Convert Email to PDF with cURL
This cURL walkthrough uses the public pdfRest API directly from a shell script. It converts an Email (.eml) file into a PDF through the pdfRest Convert to PDF API Tool. The complete sample is included below so cURL developers can see the file handling, request construction, and response path together.
Why Email to PDF with cURL?
Shell scripts often sit at the edge of intake jobs, release processes, and operations tooling. Converting an .eml file there creates a document artifact that can move through the same storage, review, and delivery steps as other PDFs.
A compliance export job, for instance, can receive a mailbox archive item, send the selected message to pdfRest, and save the resulting PDF beside a case bundle. The script stays focused on the request and resource response instead of embedding a mail-rendering engine.
Because the call is standard multipart HTTP, the same command can be run interactively for a one-off record or placed in a scheduled shell workflow. The output ID provides the handoff point for an immediate download or a later pdfRest request.
cURL Code Example for Email to PDF
#!/bin/sh # By default, we use the US-based API service. This is the primary endpoint for global use. API_URL="https://api.pdfrest.com" # For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. # For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work # API_URL="https://eu-api.pdfrest.com" # This sample converts an Email (.eml) file to PDF by sending it directly in a # multipart /pdf request. INPUT_PATH="/path/to/sample.eml" curl --location "$API_URL/pdf" \ --header "Accept: application/json" \ --header "Content-Type: multipart/form-data" \ --header "Api-Key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --form "file=@$INPUT_PATH;type=message/rfc822" \ --form "output=pdf_from_email"
Source: View the sample on GitHub
Breaking Down the Code
Configure the service and input
# By default, we use the US-based API service. This is the primary endpoint for global use. API_URL="https://api.pdfrest.com" # For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below. # For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work # API_URL="https://eu-api.pdfrest.com"
For this Email to PDF example, cURL sends the multipart request to /pdf. cURL needs no language package installation. The sample keeps the service URL, API key, input path, and output name together near the top of the shell script so those values can be replaced before the request is sent. The sample’s placeholder path and API key make the moving pieces visible; replace them with a real local path and protected runtime credential before using the request.
Upload the Email File
--header "Accept: application/json" \ --header "Content-Type: multipart/form-data" \ --header "Api-Key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --form "file=@$INPUT_PATH;type=message/rfc822" \ --form "output=pdf_from_email"
The cURL request places the Email source in the multipart part named file. Retain its .eml filename extension because Convert to PDF uses the uploaded name to identify the source type, then use the optional output field to choose the generated resource name without a PDF extension.
Build the multipart request
--header "Content-Type: multipart/form-data" \ --header "Api-Key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --form "file=@$INPUT_PATH;type=message/rfc822" \ --form "output=pdf_from_email"
For the Email to PDF form, each --form option creates one multipart field. cURL reads file fields from disk when their value begins with @, while ordinary quoted values become text fields.
Read the output resource
# multipart /pdf request. INPUT_PATH="/path/to/sample.eml" curl --location "$API_URL/pdf" \ --header "Accept: application/json" \ --header "Content-Type: multipart/form-data" \ --header "Api-Key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \ --form "file=@$INPUT_PATH;type=message/rfc822" \ --form "output=pdf_from_email"
After the Email to PDF call, the command prints the JSON response. Read outputId to retain the generated resource for a later call or download it from the returned URL before the service retention period ends.
Beyond the Tutorial
In this cURL tutorial, you converted an Email file into a PDF resource with a direct multipart request. The pattern gives a message-based workflow a document output that can be reviewed, downloaded, or passed to another pdfRest operation.
Try representative email to pdf inputs in API Lab. For the authoritative request fields, accepted values, and response contract, consult the Convert to PDF API Tool documentation. The same request pattern can then be adapted to your cURL application’s error handling, retention policy, and delivery workflow.
The repository also provides a JSON-payload Email-to-PDF version for cURL. It uploads the message first and then posts its resource ID to /pdf, which is useful when an application stages inputs for several later operations. View the JSON-payload sample on GitHub.