PDF from Email
Description: Convert email files (MSG or EML) code into PDF. Extracts attachments (if any) from input email and embeds into PDF as pdf attachments.
Status Errors
Code | Description |
---|---|
200 | The request has succeeded |
400 | bad input parameters |
401 | unauthorized |
403 | not enough credits |
405 | Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If a file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info |
Example
Sample Request:
! Don’t forget to set x-api-key
url param or http header param (preferred) to API key, get yours here
Available Methods
- [POST] /pdf/convert/from/email
- [POST] /pdf/convert/from/email (with orientation and paper size)
- [POST] /email/decode
- [POST] /email/extract-attachments
[POST] /pdf/convert/from/email
Generate PDF from MSG
or EML
file and creates PDF file with email and attachments (if any). You can set the following params:
url
required. Link to input EML or MSG file to be converted. You can pass link to file from Google Drive, Dropbox or another online file service that can generate shareable links. You can also use built-in PDF.co cloud storage located at https://app.pdf.co/files or upload your file as temporary file right before making this API call (seeUpload and Manage Files
section for more details on uploading files via API).embedAttachments
optional.True
by default. Set totrue
to automatically embeds all attachments from original input email MSG or EML fileas files into final output PDF. Set tofalse
if you don’t want to embed attachments so it will convert only the body of input email.convertAttachments
optional.true
by default. Set tofalse
if you don’t want to convert attachments from original email and want to embed them as original files (as embedded pdf attachments). Converts attachments that are supported by API (doc, docx, html, png, jpg etc) into PDF and merges into output final PDF. Non-supported file types are added as PDF attachments (Adobe Reader or another viewer maybe required to view PDF attachments).async
optional. Set totrue
to run as async job in background (recommended for heavy documents).margins
optional. set to css style margins like10px
,5mm
,5in
for all sides or5px 5px 5px 5px
(the order of margins istop
,right
,bottom
,left
).paperSize
optional. Can beLetter
,A4
,A5
,A6
or custom size in pixels, mm or inches with width and height separated by space like this:200 300
,200px 300px
,200mm 300mm
,20cm 30cm
or6in 8in
.orientation
optional. set toPortrait
orLandscape
.Portrait
by default.profiles
optional. Must be a String. Use this param to set additional configuration for fine tuning and extra options. Explore PDF.co knowledgebase for profile examples.name
optional. File name for generated output. Must be a String.expiration
(optional). Output link expiration in minutes. Default is60
(i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage. Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.- Method: POST
- URL: /v1/pdf/convert/from/email
Query parameters
No query parameters accepted.
Body payload
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
"embedAttachments": true,
"convertAttachments": true,
"paperSize": "Letter",
"name": "email-with-attachments",
"async": false,
"encrypt": false
}
Example responses
/pdf/convert/from/url (with header and footer)
JSON POST /pdf/convert/from/url
{
"url": "https://pdf-temp-files.s3.amazonaws.com/980bc13f061344809c75e83ce181851c/Contact_us.pdf",
"pageCount": 3,
"error": false,
"status": 200,
"name": "Contact_us.pdf",
"remainingCredits": 60637
}
Code Snippet
CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/email' \
--header 'x-api-key: ' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
"embedAttachments": true,
"convertAttachments": true,
"paperSize": "Letter",
"name": "email-with-attachments",
"async": false,
"encrypt": false
}'
[POST] /pdf/convert/from/email (with orientation and paper size)
url
required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly gettingToo Many Requests
orAccess Denied
error for your input url, please try to addcache:
to enable built-in url caching.httpusername
(optional) - http auth user name if required to access sourceurl
.httppassword
(optional) - http auth password if required to access sourceurl
.name
optional. File name for generated output. Must be a String.expiration
(optional). Output link expiration in minutes. Default is60
(i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage. Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.profiles
optional. Must be a String. Use this param to set additional configuration for fine tuning and extra options. Explore PDF.co knowledgebase for profile examples.
profiles
string may contain JSON string containing options like orientation, paper size, margins. Example: {'orientation': 'landscape', 'paperSize': 'letter', 'margins': '5mm'}
Available options inside profiles:
margins
optional. set to css style margins like10px
,5mm
,5in
for all sides or5px 5px 5px 5px
(the order of margins istop
,right
,bottom
,left
).paperSize
optional. Can beLetter
,A4
,A5
,A6
or custom size in pixels, mm or inches with width and height separated by space like this:200 300
,200px 300px
,200mm 300mm
,20cm 30cm
or6in 8in
.orientation
optional. set toPortrait
orLandscape
.Portrait
by default.- Method: POST
- URL: /v1/pdf/convert/from/email
Query parameters
No query parameters accepted.
Body payload
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
"embedAttachments": true,
"name": "email-with-attachments",
"async": false,
"encrypt": false,
"profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
}
Example responses
/pdf/convert/from/email with Orientation and paper Size
{
"url": "https://pdf-temp-files.s3.amazonaws.com/1baff39add874c509b2c2675ba7734fc/email-with-attachments.pdf",
"pageCount": 3,
"error": false,
"status": 200,
"name": "email-with-attachments",
"remainingCredits": 616243,
"credits": 168
}
Code Snippet
CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/email' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-to-pdf/sample.eml",
"embedAttachments": true,
"name": "email-with-attachments",
"async": false,
"encrypt": false,
"profiles": "{\"orientation\": \"landscape\", \"paperSize\": \"letter\" }"
}'
[POST] /email/decode
url
required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly gettingToo Many Requests
orAccess Denied
error for your input url, please try to addcache:
to enable built-in url caching.inline
optional.false
by default. Inasync
mode it returnsbody
with the content of the output json (with the links to the output).profiles
optional. Must be a String. Use this param to set additional configuration for fine tuning and extra options. Explore PDF.co knowledgebase for profile examples.- Method: POST
- URL: /v1/email/decode
Query parameters
No query parameters accepted.
Body payload
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml",
"inline": true,
"async": false
}
Example responses
/email/decode
{
"body": {
"from": "test@example.com",
"fromName": "",
"to": [
{
"address": "test2@example.com",
"name": ""
}
],
"cc": [],
"bcc": [],
"sentAt": null,
"receivedAt": null,
"subject": "Test email with attachments",
"bodyHtml": null,
"bodyText": "Test Email Message with 2 PDF files as attachments\r\n\r\n",
"attachmentCount": 2
},
"error": false,
"status": 200,
"name": "sample.json",
"remainingCredits": 60095
}
Code Snippet
CURL
curl --location --request POST 'https://api.pdf.co/v1/email/decode' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml",
"inline": true,
"async": false
}'
[POST] /email/extract-attachments
url
required. URL to the source file. Supports links from Google Drive, Dropbox and from built-in PDF.co files storage. For uploading files via API please check Files Upload section. If you are randomly gettingToo Many Requests
orAccess Denied
error for your input url, please try to addcache:
to enable built-in url caching.inline
optional.false
by default. Inasync
mode it returnsbody
with the content of the output json (with the links to the output).profiles
optional. Must be a String. Use this param to set additional configuration for fine tuning and extra options. Explore PDF.co knowledgebase for profile examples.- Method: POST
- URL: /v1/email/extract-attachments
Query parameters
No query parameters accepted.
Body payload
{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml",
"inline": true,
"async": false
}
Example responses
POST /email/extract-attachments
{
"body": {
"from": "test@example.com",
"subject": "Test email with attachments",
"bodyHtml": null,
"bodyText": "Test Email Message with 2 PDF files as attachments\r\n\r\n",
"attachments": [
{
"filename": "DigitalOcean.pdf",
"url": "https://pdf-temp-files.s3.amazonaws.com/2943e6bb80e646ec92e839292e95d542/DigitalOcean.pdf"
},
{
"filename": "sample.pdf",
"url": "https://pdf-temp-files.s3.amazonaws.com/e10e37fbb438432a83ece50ccdc719b3/sample.pdf"
}
]
},
"pageCount": 2,
"error": false,
"status": 200,
"name": "sample.json",
"remainingCredits": 60085
}
Code Snippet
CURL
curl --location --request POST 'https://api.pdf.co/v1/email/extract-attachments' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml",
"inline": true,
"async": false
}'
Copyright © 2016 - 2022 PDF.co