Create a batch of email messages
Creates up to 50 email messages in a single request.
POST
/
email_messages
/
batch
Create a batch of email messages
curl --request POST \
--url https://api.telnyx.com/v2/email_messages/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sandbox_mode": false,
"messages": [
{
"from": "sender@example.com",
"to": [
"recipient1@example.com"
],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": [
"recipient2@example.com"
],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
'import requests
url = "https://api.telnyx.com/v2/email_messages/batch"
payload = {
"sandbox_mode": False,
"messages": [
{
"from": "sender@example.com",
"to": ["recipient1@example.com"],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": ["recipient2@example.com"],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sandbox_mode: false,
messages: [
{
from: 'sender@example.com',
to: ['recipient1@example.com'],
subject: 'Hello 1',
text_body: 'Message 1'
},
{
from: 'sender@example.com',
to: ['recipient2@example.com'],
subject: 'Hello 2',
text_body: 'Message 2'
}
]
})
};
fetch('https://api.telnyx.com/v2/email_messages/batch', 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://api.telnyx.com/v2/email_messages/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sandbox_mode' => false,
'messages' => [
[
'from' => 'sender@example.com',
'to' => [
'recipient1@example.com'
],
'subject' => 'Hello 1',
'text_body' => 'Message 1'
],
[
'from' => 'sender@example.com',
'to' => [
'recipient2@example.com'
],
'subject' => 'Hello 2',
'text_body' => 'Message 2'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.telnyx.com/v2/email_messages/batch"
payload := strings.NewReader("{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://api.telnyx.com/v2/email_messages/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/email_messages/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"filename": "<string>",
"content_type": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"inserted_at": "2023-11-07T05:31:56Z",
"send_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"filename": "<string>",
"content_type": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"inserted_at": "2023-11-07T05:31:56Z",
"send_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"code": "reputation_suspended",
"title": "Sending Suspended",
"detail": "<string>"
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Optional opaque, unquoted key for safely retrying the same logical request. Keys must contain 1 to 255 letters, numbers, hyphens, or underscores. Generate a unique UUID v4 for each operation and reuse it only when retrying that operation with the same request. Invalid headers—including duplicate, empty, malformed, or overlong values—return 400 with error code 10015. A request already in progress with the same key returns 409; reusing the key with a different request returns 422. Only successful responses are replayed, for up to 24 hours. Do not include sensitive data in the key.
Required string length:
1 - 255Pattern:
^[A-Za-z0-9_-]{1,255}$Body
application/json
Was this page helpful?
⌘I
Create a batch of email messages
curl --request POST \
--url https://api.telnyx.com/v2/email_messages/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sandbox_mode": false,
"messages": [
{
"from": "sender@example.com",
"to": [
"recipient1@example.com"
],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": [
"recipient2@example.com"
],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
'import requests
url = "https://api.telnyx.com/v2/email_messages/batch"
payload = {
"sandbox_mode": False,
"messages": [
{
"from": "sender@example.com",
"to": ["recipient1@example.com"],
"subject": "Hello 1",
"text_body": "Message 1"
},
{
"from": "sender@example.com",
"to": ["recipient2@example.com"],
"subject": "Hello 2",
"text_body": "Message 2"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sandbox_mode: false,
messages: [
{
from: 'sender@example.com',
to: ['recipient1@example.com'],
subject: 'Hello 1',
text_body: 'Message 1'
},
{
from: 'sender@example.com',
to: ['recipient2@example.com'],
subject: 'Hello 2',
text_body: 'Message 2'
}
]
})
};
fetch('https://api.telnyx.com/v2/email_messages/batch', 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://api.telnyx.com/v2/email_messages/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'sandbox_mode' => false,
'messages' => [
[
'from' => 'sender@example.com',
'to' => [
'recipient1@example.com'
],
'subject' => 'Hello 1',
'text_body' => 'Message 1'
],
[
'from' => 'sender@example.com',
'to' => [
'recipient2@example.com'
],
'subject' => 'Hello 2',
'text_body' => 'Message 2'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api.telnyx.com/v2/email_messages/batch"
payload := strings.NewReader("{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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.post("https://api.telnyx.com/v2/email_messages/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/email_messages/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"sandbox_mode\": false,\n \"messages\": [\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient1@example.com\"\n ],\n \"subject\": \"Hello 1\",\n \"text_body\": \"Message 1\"\n },\n {\n \"from\": \"sender@example.com\",\n \"to\": [\n \"recipient2@example.com\"\n ],\n \"subject\": \"Hello 2\",\n \"text_body\": \"Message 2\"\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"filename": "<string>",
"content_type": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"inserted_at": "2023-11-07T05:31:56Z",
"send_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"data": [
{
"record_type": "email_message",
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"from": {
"email": "<string>",
"name": "<string>"
},
"to": [
{
"email": "<string>",
"name": "<string>"
}
],
"cc": [
{
"email": "<string>",
"name": "<string>"
}
],
"bcc": [
{
"email": "<string>",
"name": "<string>"
}
],
"reply_to": "<string>",
"subject": "<string>",
"template_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"template_variables": {},
"attachments": [
{
"filename": "<string>",
"content_type": "<string>"
}
],
"events": [
{
"occurred_at": "2023-11-07T05:31:56Z",
"payload": {}
}
],
"inserted_at": "2023-11-07T05:31:56Z",
"send_at": "2023-11-07T05:31:56Z",
"inline_css": true,
"sandbox": true,
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}
],
"errors": [
{
"index": 1,
"message": "<string>"
}
],
"meta": {
"total": 1,
"succeeded": 1,
"failed": 1
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "email is required"
}
]
}{
"errors": [
{
"code": "10006",
"title": "Not authorized",
"detail": "Invalid API key",
"meta": {
"url": "https://developers.telnyx.com/docs/overview/errors/10006"
}
}
]
}{
"errors": [
{
"code": "10036",
"title": "Resource is being processed",
"detail": "A request with this Idempotency-Key is already being processed.",
"source": {
"pointer": "/header/Idempotency-Key"
}
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"title": "<string>",
"detail": "<string>",
"source": {},
"meta": {}
}
],
"suppressed": [
{
"to": "jsmith@example.com",
"reason": "<string>",
"scope": "<string>",
"override_allowed": true
}
]
}{
"errors": [
{
"code": "reputation_suspended",
"title": "Sending Suspended",
"detail": "<string>"
}
]
}{
"errors": [
{
"code": "10016",
"title": "Service Unavailable",
"detail": "The email domain service is temporarily unavailable. Please try again later."
}
]
}