Preview HTML in selected email clients
/v1/emails/previewRead-only offline emulation, not a screenshot. Supply HTML or an outbound email ID; stored HTML has the same access and redaction as getEmailContent. Render untrusted output only via iframe.srcdoc with sandbox=""; the embedded CSP blocks remote assets. Results follow the requested client order. Classic Outlook is lint only (empty html). New Outlook for Windows models Outlook web; actual client behavior is unverified. Input over 256 KiB UTF-8, excessive document complexity, or combined output HTML over 4 MiB returns 413.
Needs Sent mail: read for the sender domain.
Example
import { createClient } from '@nightmail/sdk/client';
import { previewEmail } from '@nightmail/sdk';
const client = createClient({
baseUrl: 'https://nightmail.dev',
auth: scheme => scheme.scheme === 'bearer'
? process.env.NIGHTMAIL_API_KEY
: undefined,
});
const result = await previewEmail({
client,
body: {
"html": "<h1>Hello</h1><p>Your message is ready.</p>",
"clients": [
"gmail-web"
],
"theme": "light"
},
throwOnError: true,
});
console.log(result.data);curl --request POST \
--url 'https://nightmail.dev/v1/emails/preview' \
--header "Authorization: Bearer $NIGHTMAIL_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"html": "<h1>Hello</h1><p>Your message is ready.</p>",
"clients": [
"gmail-web"
],
"theme": "light"
}'Request body
EmailPreviewInputSupply exactly one source: html or emailId.
One of 2:
Variant 1html, clients, theme, device
htmlrequiredstringHTML to preview, up to 256 KiB in UTF-8.
clientsrequiredstring[]themerequiredstringdevicestringViewport width in CSS pixels: mobile 390, desktop 800. Defaults to mobile for iOS, Android and Samsung Email; otherwise desktop.
Variant 2emailId, clients, theme, device
emailIdrequiredstringOutbound email with retained HTML visible to this credential.
clientsrequiredstring[]themerequiredstringdevicestringViewport width in CSS pixels: mobile 390, desktop 800. Defaults to mobile for iOS, Android and Samsung Email; otherwise desktop.
Responses
200Success
EmailPreviewspreviewsrequiredobject[]previews[].clientrequiredstringpreviews[].htmlrequiredstringUntrusted offline document; render only as the srcdoc of an iframe with sandbox="". Empty for classic Outlook (lint only).
previews[].issuesrequiredobject[]400, 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.