Email Send and Decode#
Functions to send email (with attachments), decode email, extract attachments from email.
Note
For converting email to PDF please see PDF from Email.
Available Methods#
/email/send#
Method: POST
Endpoint: /v1/email/send
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/file1.pdf"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
The “From” field with sender name and email, e.g. |
yes |
|
The “To” field with receiver name and email, e.g. |
yes |
|
The subject for the outgoing email. |
yes |
|
The plain text version of the outgoing email message. |
no |
|
HTML version of the outgoing email message. |
no |
|
SMTP server address. |
yes |
|
SMTP port. |
yes |
|
SMTP server username |
yes |
|
SMTP server password, If you use Gmail then you need to generate an app-specific password. |
yes |
|
Set |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Query parameters#
No query parameters accepted.
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-info/sample.pdf",
"from": "John Doe <john@example.com>",
"to": "Partner <partner@example.com>",
"subject": "Check attached sample pdf",
"bodytext": "Please check the attached pdf",
"bodyHtml": "Please check the attached pdf",
"smtpserver": "smtp.gmail.com",
"smtpport": "587",
"smtpusername": "my@gmail.com",
"smtppassword": "app specific password created as https://support.google.com/accounts/answer/185833",
"async": false
}
CURL#
curl --location --request POST 'https://api.pdf.co/v1/email/send' \
--header 'Content-Type: application/json' \
--header 'x-api-key: *******************' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-info/sample.pdf",
"from": "John Doe <john@example.com>",
"to": "Partner <partner@example.com>",
"subject": "Check attached sample pdf",
"bodytext": "Please check the attached pdf",
"bodyHtml": "Please check the attached pdf",
"smtpserver": "smtp.gmail.com",
"smtpport": "587",
"smtpusername": "my@gmail.com",
"smtppassword": "app specific password created as https://support.google.com/accounts/answer/185833",
"async": false
}'
/email/decode#
Method: POST
Endpoint: /v1/email/decode
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/sample.eml"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
Set to |
no |
|
Set |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Query parameters#
No query parameters accepted.
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/email-extractor/sample.eml",
"inline": true,
"async": false
}
Response 2#
{
"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
}
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://pdfco-test-files.s3.us-west-2.amazonaws.com/email-extractor/sample.eml",
"inline": true,
"async": false
}'
/email/extract-attachments#
Method: POST
Endpoint: /v1/email/extract-attachments
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/sample.eml"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
Set to |
no |
|
Set |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Query parameters#
No query parameters accepted.
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/email-extractor/sample.eml",
"inline": true,
"async": false
}
Response 2#
{
"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
}
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://pdfco-test-files.s3.us-west-2.amazonaws.com/email-extractor/sample.eml",
"inline": true,
"async": false
}'
Code samples#
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://api.pdf.co/v1/email/send',
'headers': {
'Content-Type': 'application/json',
'x-api-key': 'ADD_YOUR_PDFco_API_KEY'
},
body: JSON.stringify({
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-info/sample.pdf",
"from": "John Doe <john@example.com>",
"to": "Partner <partner@example.com>",
"subject": "Check attached sample pdf",
"bodytext": "Please check the attached pdf",
"bodyHtml": "Please check the attached pdf",
"smtpserver": "smtp.gmail.com",
"smtpport": "587",
"smtpusername": "my@gmail.com",
"smtppassword": "app specific password created as https://support.google.com/accounts/answer/185833",
"async": false
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://api.pdf.co/v1/email/send"
payload = json.dumps({
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-info/sample.pdf",
"from": "John Doe <john@example.com>",
"to": "Partner <partner@example.com>",
"subject": "Check attached sample pdf",
"bodytext": "Please check the attached pdf",
"bodyHtml": "Please check the attached pdf",
"smtpserver": "smtp.gmail.com",
"smtpport": "587",
"smtpusername": "my@gmail.com",
"smtppassword": "app specific password created as https://support.google.com/accounts/answer/185833",
"async": False
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'ADD_YOUR_API_KEY'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
namespace PDFcoApiExample
{
class Program
{
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const String API_KEY = "***********************************";
// Direct URL of source PDF file.
const string SourceFileUrl = "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-info/sample.pdf";
// Email Details
const string From = "John Doe <john@example.com>";
const string To = "Partner <partner@example.com>";
const string Subject = "Check attached sample pdf";
const string BodyText = "Please check the attached pdf";
const string BodyHtml = "Please check the attached pdf";
const string SmtpServer = "smtp.gmail.com";
const string SmtpPort = "587";
const string SmtpUserName = "my@gmail.com";
const string SmtpPassword = "app specific password created as https://support.google.com/accounts/answer/185833";
static void Main(string[] args)
{
// Create standard .NET web client instance
WebClient webClient = new WebClient();
// Set API Key
webClient.Headers.Add("x-api-key", API_KEY);
// URL for `Email Send` API call
string url = "https://api.pdf.co/v1/email/send";
// Prepare requests params as JSON
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("url", SourceFileUrl);
parameters.Add("from", From);
parameters.Add("to", To);
parameters.Add("subject", Subject);
parameters.Add("bodytext", BodyText);
parameters.Add("bodyHtml", BodyHtml);
parameters.Add("smtpserver", SmtpServer);
parameters.Add("smtpport", SmtpPort);
parameters.Add("smtpusername", SmtpUserName);
parameters.Add("smtppassword", SmtpPassword);
// Convert dictionary of params to JSON
string jsonPayload = JsonConvert.SerializeObject(parameters);
try
{
// Execute POST request with JSON payload
string response = webClient.UploadString(url, jsonPayload);
// Parse JSON response
JObject json = JObject.Parse(response);
if (json["error"].ToObject<bool>() == false)
{
Console.WriteLine("Email Sent Successfully!");
}
else
{
Console.WriteLine(json["message"].ToString());
}
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
webClient.Dispose();
Console.WriteLine();
Console.WriteLine("Press any key...");
Console.ReadKey();
}
}
}
import java.io.*;
import okhttp3.*;
public class main {
public static void main(String []args) throws IOException{
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
// You can also upload your own file into PDF.co and use it as url. Check "Upload File" samples for code snippets: https://github.com/bytescout/pdf-co-api-samples/tree/master/File%20Upload/
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("url", "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/email-extractor/sample.eml")
.build();
Request request = new Request.Builder()
.url("https://api.pdf.co/v1/email/extract-attachments")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("x-api-key", "{{x-api-key}}")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
}
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.pdf.co/v1/email/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-info/sample.pdf",
"from": "John Doe <john@example.com>",
"to": "Partner <partner@example.com>",
"subject": "Check attached sample pdf",
"bodytext": "Please check the attached pdf",
"bodyHtml": "Please check the attached pdf",
"smtpserver": "smtp.gmail.com",
"smtpport": "587",
"smtpusername": "my@gmail.com",
"smtppassword": "app specific password created as https://support.google.com/accounts/answer/185833",
"async": false
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: ADD_YOUR_PDFco_KEY_HERE'
),
));
$response = json_decode(curl_exec($curl));
curl_close($curl);
echo "<h2>Output:</h2><pre>", var_export($response, true), "</pre>";
?>
On Github#
Footnotes
- 1(1,2,3)
Supports publicly accessible links from any source, including Google Drive, Dropbox, and PDF.co Built-In Files Storage. To upload files via the API, check out the File Upload section. Note: If you experience intermittent Access Denied or Too Many Requests errors, please try adding
cache:
to enable built-in URL caching (e.g.,cache:https://example.com/file1.pdf
). For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.- 2(1,2,3)
Main response codes as follows:
Code
Description
200
Success
400
Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.
401
Unauthorized
402
Not enough credits
445
Timeout error. To process large documents or files please use asynchronous mode (set the
async
parameter totrue
) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using thepages
parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.Note
For more see the complete list of available response codes.
- 3(1,2,3)
PDF.co Request size: API requests do not support request sizes of more than
4
megabytes in size. Please ensure that request sizes do not exceed this limit.