ZapSMTP / Docs / EmailsResponse
Send a batch
POST/v1/emails/batch
Send 1-100 emails in one request.
Requires a full-access or sending-access key. Test keys follow the same rules as for sending.
Per-email error codes use the same classification as POST /emails (domain_not_verified, restricted_api_key, rate_limit_exceeded, monthly_quota_exceeded, etc. appear inside errors[] rather than as the HTTP status). Emails are sent concurrently (up to 16 at a time); each email may have its own scheduled_at.
Body: length 1-100 else 422 invalid_parameter "batch must contain 1 to 100 emails"
An item of data carries reply_to when reply tracking is on for that email.
Headers
x-batch-validationstring- strict (default) | permissive (case-insensitive). strict: if any email fails validation nothing is sent and 422 is returned. permissive: valid emails are sent; invalid ones are reported in errors.
Idempotency-Keystring- optional, 1-256 bytes
Body parameters
[ ]object[]required- 1–100 emails. Each item takes the fields of Send an email.
Errors
validation_errorHTTP 400- invalid JSON or x-batch-validation not strict/permissive
invalid_idempotency_keyHTTP 400- Idempotency-Key must be 1 to 256 bytes
idempotency_key_reusedHTTP 409idempotency_request_in_progressHTTP 409payload_too_largeHTTP 413invalid_parameterHTTP 422- batch size outside 1-100
validation_errorHTTP 422- strict mode, any email invalid
service_unavailableHTTP 503- too many large bodies in flight
curl -X POST 'https://zapsmtp.xyz/v1/emails/batch' \
-H "Authorization: Bearer $ZAP_API_KEY" \
-H 'Content-Type: application/json' \
-d '[
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz"
],
"subject": "Hello Ann",
"text": "Hi Ann!"
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz"
],
"subject": "Hello Bob",
"text": "Hi Bob!"
}
]'const res = await fetch('https://zapsmtp.xyz/v1/emails/batch', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ZAP_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify([
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz"
],
"subject": "Hello Ann",
"text": "Hi Ann!"
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz"
],
"subject": "Hello Bob",
"text": "Hi Bob!"
}
]),
});
// 204 No Content (e.g. a delete) has no body
const data = res.status === 204 ? null : await res.json();
if (!res.ok) throw new Error(`${data.name}: ${data.message}`);
console.log(data);import os
import requests
res = requests.post(
"https://zapsmtp.xyz/v1/emails/batch",
headers={"Authorization": f"Bearer {os.environ['ZAP_API_KEY']}"},
json=[
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz",
],
"subject": "Hello Ann",
"text": "Hi Ann!",
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz",
],
"subject": "Hello Bob",
"text": "Hi Bob!",
},
],
timeout=30,
)
res.raise_for_status()
print(res.json() if res.status_code != 204 else "deleted")<?php
$ch = curl_init('https://zapsmtp.xyz/v1/emails/batch');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('ZAP_API_KEY'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
[
'from' => 'Acme <hello@acme.com>',
'to' => [
'delivered@simulator.zapsmtp.xyz',
],
'subject' => 'Hello Ann',
'text' => 'Hi Ann!',
],
[
'from' => 'Acme <hello@acme.com>',
'to' => [
'bounced@simulator.zapsmtp.xyz',
],
'subject' => 'Hello Bob',
'text' => 'Hi Bob!',
],
]),
]);
$data = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status >= 400) {
throw new RuntimeException($data['message']);
}
print_r($data);package main
import (
"fmt"
"io"
"net/http"
"os"
"strings"
)
func main() {
body := strings.NewReader(`[
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz"
],
"subject": "Hello Ann",
"text": "Hi Ann!"
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz"
],
"subject": "Hello Bob",
"text": "Hi Bob!"
}
]`)
req, err := http.NewRequest(
"POST",
"https://zapsmtp.xyz/v1/emails/batch",
body,
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("ZAP_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(res.Status, string(out))
}require 'net/http'
require 'json'
uri = URI('https://zapsmtp.xyz/v1/emails/batch')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "Bearer #{ENV.fetch('ZAP_API_KEY')}"
req['Content-Type'] = 'application/json'
req.body = [
{
from: "Acme <hello@acme.com>",
to: [
"delivered@simulator.zapsmtp.xyz"
],
subject: "Hello Ann",
text: "Hi Ann!"
},
{
from: "Acme <hello@acme.com>",
to: [
"bounced@simulator.zapsmtp.xyz"
],
subject: "Hello Bob",
text: "Hi Bob!"
}
].to_json
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }
puts res.code, (JSON.parse(res.body) unless res.body.to_s.empty?)import java.net.URI;
import java.net.http.*;
public class ZapRequest {
public static void main(String[] args) throws Exception {
var request = HttpRequest.newBuilder(URI.create("https://zapsmtp.xyz/v1/emails/batch"))
.header("Authorization", "Bearer " + System.getenv("ZAP_API_KEY"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("""
[
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz"
],
"subject": "Hello Ann",
"text": "Hi Ann!"
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz"
],
"subject": "Hello Bob",
"text": "Hi Bob!"
}
]"""))
.build();
var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}using System.Net.Http.Headers;
using System.Text;
using var http = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://zapsmtp.xyz/v1/emails/batch");
request.Headers.Authorization = new AuthenticationHeaderValue(
"Bearer", Environment.GetEnvironmentVariable("ZAP_API_KEY"));
request.Content = new StringContent("""
[
{
"from": "Acme <hello@acme.com>",
"to": [
"delivered@simulator.zapsmtp.xyz"
],
"subject": "Hello Ann",
"text": "Hi Ann!"
},
{
"from": "Acme <hello@acme.com>",
"to": [
"bounced@simulator.zapsmtp.xyz"
],
"subject": "Hello Bob",
"text": "Hi Bob!"
}
]
""", Encoding.UTF8, "application/json");
var response = await http.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");Set
ZAP_API_KEY in your environment.Response 200 OK
{
"data": [
{
"index": 0,
"id": "019a1f2e-7c3b-7d41-9a52-0c4b8e6f1a23"
},
{
"index": 2,
"id": "019a1f2e-7c3c-7a10-8b21-4d5e6f7a8b9c",
"suppressed": [
"old@example.org"
]
}
],
"errors": [
{
"index": 1,
"code": "missing_required_field",
"message": "subject is required"
}
]
}