Link Search Menu Expand Document

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

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout 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 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

Go To Samples

[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 (see Upload and Manage Files section for more details on uploading files via API).
  • embedAttachments optional. True by default. Set to true to automatically embeds all attachments from original input email MSG or EML fileas files into final output PDF. Set to false if you don’t want to embed attachments so it will convert only the body of input email.
  • convertAttachments optional. true by default. Set to false 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 to true to run as async job in background (recommended for heavy documents).
  • margins optional. set to css style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
  • paperSize optional. Can be Letter, 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 or 6in 8in.
  • orientation optional. set to Portrait or Landscape. Portrait by default.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.
  • name optional. File name for generated output. Must be a String.
  • expiration (optional). Output link expiration in minutes. Default is 60 (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.

Description

  • 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

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 getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • httpusername (optinal) - http auth user name if required to access source url.
  • httppassword (optinal) - http auth password if required to access source url.
  • name optional. File name for generated output. Must be a String.
  • expiration (optional). Output link expiration in minutes. Default is 60 (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. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for 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 like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
  • paperSize optional. Can be Letter, 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 or 6in 8in.
  • orientation optional. set to Portrait or Landscape. Portrait by default.

Description

  • 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 getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • 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"
}

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"
}'

[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 getting Too Many Requests or Access Denied error for your input url, please try to add cache: to enable built-in url caching.
  • profiles optional. Must be a String. You can set additional and extra options using this parameter that allows you to set custom configuration. See profiles samples for examples.

Description

  • 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"
}

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"
}'

Samples