Send email
/v1/emails/sendFront-door admission and content screening: Hosted sending checks validation, recipient suppression/consent, balance, limits, and the outbound harm screen synchronously before queueing. Failing messages return an immediate error (422 RECIPIENT_INELIGIBLE, 422 CONTENT_REJECTED_SPAM, 422 CONTENT_TOO_LARGE_TO_SCREEN, or retryable 503 CONTENT_SCREEN_UNAVAILABLE with Retry-After when no mandatory classifier is configured) and nothing is queued; during a temporary outage of both classifiers, eligible mail is accepted (202) and held unscreened until a classifier answers. Screened-text limits: at most 65,536 UTF-8 bytes per message (installation default) and 150 distinct link hosts (3,000 bytes of host names), counting link labels that name another host; over either limit, error.details[0] holds { screenedBytes, limitBytes } or { linkHosts, linkHostLimit } (plus index in a batch). Marketing ramp: on Hosted sending, a workspace still ramping up (a new sender, exempt and first-party ones included) sends kind: marketing at most its ramp step's hourly ceiling (1,000, 2,500, 5,000, 10,000, 20,000, 40,000, 75,000, 150,000, 300,000 recipients an hour), shared with its campaigns. A send that would cross it is refused with nothing queued (a batch as a whole): retryable 429 RAMP_LIMIT_REACHED, with Retry-After (seconds until more room opens) and error.details[0] holding { step, steps, ceilingPerHour, usedThisHour, fitsNow, requested, stepOpensAt }. A scheduled marketing send is refused the same way when it is scheduled if it is larger than the step's whole ceiling, or if with the marketing already scheduled within 24 hours either side of its time it is more than the step sends in 24 hours (error.details[0] adds { scheduledBacklog, dailyBudget }); one that fits is held at its time until its hour has room (it stays scheduled, scheduledAt moving to when it tries again, with a dispatch_deferred event), never rejected for the ramp. While the workspace ramps and a campaign of it is stopped by the automatic pause, the list probe or the ramp's check (LIST_QUALITY, BOUNCE_RATE_HIGH, COMPLAINT_RATE_HIGH) and not resumed or canceled, marketing sends and schedules are refused with 409 RAMP_PAUSED (not retryable; error.details[0] holds { campaignId, pauseCode }): review and resume that campaign first. For a large list, send a campaign instead: campaigns are paced automatically. Transactional mail is never ramped or paused by it. Built-in domain (Hosted): every workspace has a subdomain of Nightmail's own domain (connection.builtinDomain in GET /v1/me) that sends until the workspace verifies a domain of its own: plain transactional email sent now, without attachments, custom headers, a stored template or a Reply-To elsewhere (422 BUILTIN_DOMAIN_UNSUPPORTED, once, listing every such field in error.details[].unsupported), to the recipients the installation allows (on hosted Nightmail, for now, only the verified sign-in addresses of the workspace's members: 422 BUILTIN_DOMAIN_RECIPIENT names any other recipient in error.details[0].notMembers; add a domain of your own to email anyone; where connection.builtinDomain.repliesToSenders is true, a thread reply (replyToInboundThread) may also go once to the authenticated sender of the message it answers, never to another built-in domain or to Nightmail's own addresses but its support), within a per-minute and a daily recipient cap (429 BUILTIN_DOMAIN_LIMIT), screened like a new sender's mail. Once a domain of its own verifies it stops sending and answers 409 OWN_DOMAIN_VERIFIED, with the same address at that domain to use instead in error.details[0].suggestedFrom (and every verified domain in verifiedDomains). Attachments: One file is at most 8 MiB decoded when sent as base64 in JSON (POST /v1/attachments), or 25 MiB as raw bytes (POST /v1/attachments/upload, with the name URI-encoded in X-Nightmail-Filename and the type in Content-Type). One email carries at most 100 files and 25 MiB of them together, decoded. A workspace keeps at most 100 GiB of uploaded files. For anything larger, link to the file from the email. filename: the file's name: 1 to 200 characters, without control characters, / or \, and not an extension Amazon SES refuses (.exe, .bat, .js, .vbs and others). contentType: a MIME type such as application/pdf (type/subtype, optionally with ; parameters), at most 78 printable ASCII characters. disposition: attachment (the default) or inline; inline needs a contentId: 1 to 78 letters, digits, _ . @ or -, for an inline image the HTML shows as cid:<contentId>, unique within the email. Upload each file once, then list its ID in the email's attachments. A send with attachment problems is refused once, naming every problem: error.details lists each with its email (index, in a batch), attachment (its position in attachments), id, filename, code and message. Hosted senders on probation attach only standard types (images, PDF, office documents, archives, audio, video, plain text) whose name, declared type and content agree, inline only PNG, JPEG, GIF, WebP or BMP images, and never SVG.
Needs Send email for the sender domain.
Example
import { createClient } from '@nightmail/sdk/client';
import { sendEmail } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await sendEmail({
client,
body: {
"from": "sender@example.com",
"to": "recipient@example.com",
"cc": [],
"bcc": [],
"replyTo": [],
"kind": "transactional",
"attachments": [],
"subject": "Hello from Nightmail",
"text": "Your message is ready."
},
throwOnError: true,
});
console.log(result.data);curl --request POST \
--url 'https://nightmail.dev/v1/emails/send' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"from": "sender@example.com",
"to": "recipient@example.com",
"cc": [],
"bcc": [],
"replyTo": [],
"kind": "transactional",
"attachments": [],
"subject": "Hello from Nightmail",
"text": "Your message is ready."
}'Parameters
Idempotency-Keyheader · stringOptional. Makes retries safe. Repeating a request with the same key and the same body returns the original result without performing the write again. While the first request with a key is still running, a duplicate returns 409 IDEMPOTENCY_IN_PROGRESS with Retry-After: retry with the same key, never a new one. Reusing a key with a different body returns 409 IDEMPOTENCY_CONFLICT. Keys are scoped to the API key and request path. A send's key is kept at least 30 days from the request, as long as the log of the emails it queued; then it is deleted, and the same key is a new request that sends again. A scheduled send's key is kept at least 60 days, after which a repeat is refused because its time has passed. Without a key, every request is processed, so a retried send can deliver twice.
Request body
SendEmailInputfromrequiredstringAn address at a domain verified in this workspace, or at a subdomain of one — either a bare address or "Display Name <address>" (or set fromName separately). Hosted: also any address at the workspace’s built-in domain (connection.builtinDomain in GET /v1/me) until a domain of its own verifies.
fromNamestringtorequiredstring or string[]ccstring[]bccstring[]replyTostring[]regionstringUsually omitted: hosted Nightmail sends from the region bound to the sender domain, and a different value fails with SENDER_REGION_MISMATCH. Self-hosted installations default to their default region.
kindstringmarketing adds Nightmail's footer (an Unsubscribe link, with the workspace's postal address under it when it has one) and the one-click List-Unsubscribe headers.
subjectstringhtmlstringtextstringtemplateobjectUses native SES stored-template rendering and snapshots its rendered MIME. SES does not automatically escape HTML; callers must escape untrusted HTML-context values. Simulated deployments do not render AWS templates.
template.namerequiredstringtemplate.dataobjectJSON substitution data, including nested objects and arrays, is passed unchanged to SES. SES stored templates do not automatically escape HTML: callers must escape untrusted values for their HTML context. Maximum serialized JSON length: 262,144 characters.
attachmentsstring[]IDs of files uploaded first (uploadAttachment). One file is at most 8 MiB decoded when sent as base64 in JSON (POST /v1/attachments), or 25 MiB as raw bytes (POST /v1/attachments/upload, with the name URI-encoded in X-Nightmail-Filename and the type in Content-Type). One email carries at most 100 files and 25 MiB of them together, decoded. A workspace keeps at most 100 GiB of uploaded files. For anything larger, link to the file from the email.
trackingbooleanheadersobject[]Extra MIME headers, 8 KB total. The 15-header limit includes generated headers (two for marketing and any mailbox threading headers). Any name is allowed except headers Nightmail controls: From, Sender, Reply-To, Return-Path, To, Cc, Bcc, Subject, Date, Message-ID, MIME-Version, Content-*, DKIM-*, ARC-*, Authentication-Results, Received*, Resent-*, X-SES-*, List-Unsubscribe*, Auto-Submitted, and reply, receipt, trace and transport headers (Mail-Reply-To, Mail-Followup-To, Followup-To, Disposition-Notification-*, Return-Receipt-To, Errors-To, Bounces-To, Delivered-To, X-Original-To, DomainKey-*, Feedback-ID, TLS-Required, BIMI-*, Autocrypt*, OpenPGP). In-Reply-To and References must be <id@domain> Message-IDs and thread the message in the recipient's mail client.
headers[].namerequiredstringheaders[].valuerequiredstringunsubscribeobjectkind transactional only (422 UNSUBSCRIBE_REQUIRES_TRANSACTIONAL on marketing, where Nightmail manages unsubscribe headers). Writes List-Unsubscribe and List-Unsubscribe-Post: List-Unsubscribe=One-Click headers for apps managing their own notification opt-outs.
unsubscribe.urlrequiredstringHTTPS URL for RFC 8058 one-click unsubscribe (POST List-Unsubscribe=One-Click).
topicIdstringkind marketing only (422 TOPIC_REQUIRES_MARKETING otherwise): the topic it is about (listTopics). A recipient who opted out of the topic is refused (reason topic_unsubscribed), and its one-click unsubscribe opts out of this topic only.
screenbooleanRequest outbound harm screening at accept time for live transactional mail. Hosted live screening is operator-controlled and cannot be disabled by setting this field to false. Simulated mail is not screened. A positive reject verdict fails the request synchronously with 422 CONTENT_REJECTED_SPAM (nothing queued); during a temporary outage of both classifiers, the message is accepted (202) and held unscreened until a classifier answers. Mandatory Hosted screening with no classifier configured returns retryable 503 CONTENT_SCREEN_UNAVAILABLE with Retry-After.
replyAddressIdstringTrack a conversation through this receivable address. Use explicit subject and text/html. Requires unrestricted manage permission; From and Reply-To must belong to the address.
replyMailboxIdstringLegacy spelling of replyAddressId.
scheduledAtstringSend at this time instead of now: an RFC 3339 instant with Z or an offset, such as 2026-11-20T09:00:00Z; times without an offset are refused, and the time is returned in UTC. From now (up to a minute in the past, which sends at once) to 30 days ahead; up to 100,000 scheduled emails may wait per workspace (SCHEDULED_EMAIL_LIMIT_EXCEEDED). Content screening and suppression are checked at accept time; sending limits and the balance apply at scheduledAt, when an email they refuse is rejected with their code (email.rejected), except Hosted marketing its ramp hour has no room for, which is held until there is (RAMP_LIMIT_REACHED in sendEmail's description). Not with replyAddressId.
Responses
202Success
SingleEmailQueuedFor tracked sends, id is the transactional receipt, inboundMessageId identifies the stored message, and threadId identifies its conversation.
idrequiredstringstatusrequiredstringsimulatedrequiredbooleanscreenobjectContent-screen outcome recorded at accept time when screening applies.
screen.statusrequiredstringwarningsobject[]Recipients whose address looks risky (a disposable inbox, a mistyped provider, a role address): the email was queued anyway. Campaigns and marketing sends skip risky contacts.
warnings[].emailrequiredstringwarnings[].riskrequiredstringwarnings[].suggestionrequiredstring or nullscheduledAtstringA scheduled send: when it goes (UTC).
inboundMessageIdstringmailboxMessageIdstringLegacy alias for inboundMessageId.
threadIdstring400, 401, 403, 404, 409, 413, 422, 429, 500, 503Request failed; use error.code and requestId to diagnose.
ApiErrorerrorrequiredobjecterror.coderequiredstringerror.messagerequiredstringerror.requestIdrequiredstringerror.fieldstringerror.retryablerequiredbooleanerror.resetAtstringNext capacity change for a Hosted rolling send limit.
error.detailsobject[]Every problem found, when there is more than one part, such as rule diagnostics with rule, line, column, message and hint, or a measurement, such as CONTENT_TOO_LARGE_TO_SCREEN with screenedBytes and limitBytes (and index in a batch).
error.requiredobjectOn a 403 permission refusal: what the request needs that this credential lacks. The Nightmail-Required-Permission header says the same.