curl --request PATCH \
--url https://{dsn}/api/v1/{account_id}/drafts/{draft_id} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"cc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"bcc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"reply_to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"from": {
"display_name": "<string>",
"email": "<string>"
},
"subject": "<string>",
"html": "<string>",
"plain_text": "<string>",
"reply_to_message_id": "<string>",
"custom_headers": [
{
"name": "<string>",
"value": "<string>"
}
],
"metadata": "<string>",
"tracking_options": {
"opens": true,
"links": true,
"label": "<string>",
"custom_domain": "<string>"
},
"attachments": [
{
"content": "<string>",
"filename": "<string>",
"content_type": "<string>"
}
]
}
'import requests
url = "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}"
payload = {
"to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"cc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"bcc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"reply_to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"from": {
"display_name": "<string>",
"email": "<string>"
},
"subject": "<string>",
"html": "<string>",
"plain_text": "<string>",
"reply_to_message_id": "<string>",
"custom_headers": [
{
"name": "<string>",
"value": "<string>"
}
],
"metadata": "<string>",
"tracking_options": {
"opens": True,
"links": True,
"label": "<string>",
"custom_domain": "<string>"
},
"attachments": [
{
"content": "<string>",
"filename": "<string>",
"content_type": "<string>"
}
]
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
to: [{email: 'jsmith@example.com', display_name: '<string>'}],
cc: [{email: 'jsmith@example.com', display_name: '<string>'}],
bcc: [{email: 'jsmith@example.com', display_name: '<string>'}],
reply_to: [{email: 'jsmith@example.com', display_name: '<string>'}],
from: {display_name: '<string>', email: '<string>'},
subject: '<string>',
html: '<string>',
plain_text: '<string>',
reply_to_message_id: '<string>',
custom_headers: [{name: '<string>', value: '<string>'}],
metadata: '<string>',
tracking_options: {opens: true, links: true, label: '<string>', custom_domain: '<string>'},
attachments: [{content: '<string>', filename: '<string>', content_type: '<string>'}]
})
};
fetch('https://{dsn}/api/v1/{account_id}/drafts/{draft_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'to' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'cc' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'bcc' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'reply_to' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'from' => [
'display_name' => '<string>',
'email' => '<string>'
],
'subject' => '<string>',
'html' => '<string>',
'plain_text' => '<string>',
'reply_to_message_id' => '<string>',
'custom_headers' => [
[
'name' => '<string>',
'value' => '<string>'
]
],
'metadata' => '<string>',
'tracking_options' => [
'opens' => true,
'links' => true,
'label' => '<string>',
'custom_domain' => '<string>'
],
'attachments' => [
[
'content' => '<string>',
'filename' => '<string>',
'content_type' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}"
payload := strings.NewReader("{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://{dsn}/api/v1/{account_id}/drafts/{draft_id}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{dsn}/api/v1/{account_id}/drafts/{draft_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"object": "DraftCreated",
"id": "<string>",
"account_id": "<string>",
"draft_id": "<string>",
"previous_draft_id": "<string>",
"message_id": "<string>",
"tracking_id": "<string>"
}{
"status": 400,
"type": "errors/invalid_parameters",
"title": "Invalid parameters",
"detail": "limit must be between 1 and 250"
}{
"status": 401,
"type": "errors/invalid_credentials",
"title": "Invalid credentials",
"detail": "the mail provider rejected the credentials: invalid_grant"
}{
"status": 404,
"type": "errors/not_found",
"title": "Not found",
"detail": "email email_94a0d77db739407e932c3b97fef44aac not found"
}{
"status": 502,
"type": "errors/provider_error",
"title": "Mail provider error",
"detail": "timed out talking to imap.example.com"
}Update a draft
The fields you send replace the draft’s; the rest is kept. The draft is saved again in the
mailbox, so it gets a new id (the old one no longer works).
curl --request PATCH \
--url https://{dsn}/api/v1/{account_id}/drafts/{draft_id} \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"cc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"bcc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"reply_to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"from": {
"display_name": "<string>",
"email": "<string>"
},
"subject": "<string>",
"html": "<string>",
"plain_text": "<string>",
"reply_to_message_id": "<string>",
"custom_headers": [
{
"name": "<string>",
"value": "<string>"
}
],
"metadata": "<string>",
"tracking_options": {
"opens": true,
"links": true,
"label": "<string>",
"custom_domain": "<string>"
},
"attachments": [
{
"content": "<string>",
"filename": "<string>",
"content_type": "<string>"
}
]
}
'import requests
url = "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}"
payload = {
"to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"cc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"bcc": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"reply_to": [
{
"email": "jsmith@example.com",
"display_name": "<string>"
}
],
"from": {
"display_name": "<string>",
"email": "<string>"
},
"subject": "<string>",
"html": "<string>",
"plain_text": "<string>",
"reply_to_message_id": "<string>",
"custom_headers": [
{
"name": "<string>",
"value": "<string>"
}
],
"metadata": "<string>",
"tracking_options": {
"opens": True,
"links": True,
"label": "<string>",
"custom_domain": "<string>"
},
"attachments": [
{
"content": "<string>",
"filename": "<string>",
"content_type": "<string>"
}
]
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.patch(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PATCH',
headers: {'X-API-KEY': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
to: [{email: 'jsmith@example.com', display_name: '<string>'}],
cc: [{email: 'jsmith@example.com', display_name: '<string>'}],
bcc: [{email: 'jsmith@example.com', display_name: '<string>'}],
reply_to: [{email: 'jsmith@example.com', display_name: '<string>'}],
from: {display_name: '<string>', email: '<string>'},
subject: '<string>',
html: '<string>',
plain_text: '<string>',
reply_to_message_id: '<string>',
custom_headers: [{name: '<string>', value: '<string>'}],
metadata: '<string>',
tracking_options: {opens: true, links: true, label: '<string>', custom_domain: '<string>'},
attachments: [{content: '<string>', filename: '<string>', content_type: '<string>'}]
})
};
fetch('https://{dsn}/api/v1/{account_id}/drafts/{draft_id}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PATCH",
CURLOPT_POSTFIELDS => json_encode([
'to' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'cc' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'bcc' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'reply_to' => [
[
'email' => 'jsmith@example.com',
'display_name' => '<string>'
]
],
'from' => [
'display_name' => '<string>',
'email' => '<string>'
],
'subject' => '<string>',
'html' => '<string>',
'plain_text' => '<string>',
'reply_to_message_id' => '<string>',
'custom_headers' => [
[
'name' => '<string>',
'value' => '<string>'
]
],
'metadata' => '<string>',
'tracking_options' => [
'opens' => true,
'links' => true,
'label' => '<string>',
'custom_domain' => '<string>'
],
'attachments' => [
[
'content' => '<string>',
'filename' => '<string>',
'content_type' => '<string>'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"X-API-KEY: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://{dsn}/api/v1/{account_id}/drafts/{draft_id}"
payload := strings.NewReader("{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}")
req, _ := http.NewRequest("PATCH", url, payload)
req.Header.Add("X-API-KEY", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.patch("https://{dsn}/api/v1/{account_id}/drafts/{draft_id}")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://{dsn}/api/v1/{account_id}/drafts/{draft_id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Patch.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"cc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"bcc\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"reply_to\": [\n {\n \"email\": \"jsmith@example.com\",\n \"display_name\": \"<string>\"\n }\n ],\n \"from\": {\n \"display_name\": \"<string>\",\n \"email\": \"<string>\"\n },\n \"subject\": \"<string>\",\n \"html\": \"<string>\",\n \"plain_text\": \"<string>\",\n \"reply_to_message_id\": \"<string>\",\n \"custom_headers\": [\n {\n \"name\": \"<string>\",\n \"value\": \"<string>\"\n }\n ],\n \"metadata\": \"<string>\",\n \"tracking_options\": {\n \"opens\": true,\n \"links\": true,\n \"label\": \"<string>\",\n \"custom_domain\": \"<string>\"\n },\n \"attachments\": [\n {\n \"content\": \"<string>\",\n \"filename\": \"<string>\",\n \"content_type\": \"<string>\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"object": "DraftCreated",
"id": "<string>",
"account_id": "<string>",
"draft_id": "<string>",
"previous_draft_id": "<string>",
"message_id": "<string>",
"tracking_id": "<string>"
}{
"status": 400,
"type": "errors/invalid_parameters",
"title": "Invalid parameters",
"detail": "limit must be between 1 and 250"
}{
"status": 401,
"type": "errors/invalid_credentials",
"title": "Invalid credentials",
"detail": "the mail provider rejected the credentials: invalid_grant"
}{
"status": 404,
"type": "errors/not_found",
"title": "Not found",
"detail": "email email_94a0d77db739407e932c3b97fef44aac not found"
}{
"status": 502,
"type": "errors/provider_error",
"title": "Mail provider error",
"detail": "timed out talking to imap.example.com"
}Authorizations
Your access token, from your dashboard under API keys.
Path Parameters
The account's acc_… id.
The drf_… id from creation, or the synced draft's email_… id.
Body
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
The Reply-To header's addresses.
Show child attributes
Show child attributes
Sender name; email can set a send-as alias.
Show child attributes
Show child attributes
HTML body.
Plain-text body (made from html when left out).
The email you answer: its Message-ID, or its email_… id.
X-…, List-Unsubscribe, List-Unsubscribe-Post, Auto-Submitted (no, auto-replied, auto-generated, auto-notified) or Reply-To.
Show child attributes
Show child attributes
Your note about this email (never in the email), returned as sent_by.metadata on its Sent copy.
1000Show child attributes
Show child attributes
Show child attributes
Show child attributes