Skip to content
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

email-sdk send

Build one message from flags or JSON, validate it with the selected adapter, and optionally send it.

Safe dry run

Dry run creates the real adapter with placeholder credentials where needed, calls client.validate, and prints { ok, adapter, message }. It does not call the adapter send method. Attachment output includes paths and metadata, never file contents.

Message flags

Flag Behavior
--from Sender address
--to Comma-separated recipients
--subject Subject
--text, --html At least one body
--cc, --bcc, --reply-to Comma-separated addresses
--header "Name: value" Repeatable lossless headers
--tag name=value Repeatable tags
--metadata key=value Repeatable provider metadata, parsed as strings
--attachment path[:type] Repeatable server-side files; --attach also works
--message path Start from an EmailMessage JSON file; explicit flags override fields
--send-at RFC 3339 schedule for capable adapters
--dry-run Validate and print without sending
--json Print { ok: true, result } on success and { ok: false, error } on failure, both on stdout

Adapter flags

Common credential flags include --api-key, --server-token, and --base-url. Cloudflare adds --api-token and --account-id. Iterable adds --campaign-id, --iterable-send-at, and --allow-repeat-marketing-sends. SMTP adds host, port, TLS, and auth flags.

Run email-sdk help for the current list.

Routing flags

Flag Behavior
--fallback name,name Adapters to try in order after the primary definitely did not send. Repeated names and the primary are dropped.
--max-attempts n Attempts per adapter, including the first. Defaults to 1.

Fallback adapters read their configuration only from environment variables. Credential and connection flags such as --api-key and --base-url apply to the primary adapter. With --dry-run, the message is validated against every adapter on the route and the plan includes fallback and maxAttempts when set. With --dry-run --json, the plan is wrapped as { ok: true, result } like a real send.

As in the SDK, fallback runs only when the failure proves nothing was sent, such as a 401 or 422. A timeout or 5xx stops the route.

Live sends

Without --dry-run, the command builds the primary adapter and any fallbacks, calls client.send, and prints the normalized result as JSON. With --json, the result is wrapped as { ok: true, result }, and a failure prints { ok: false, error } with the error code, message, and, for route failures, one entry per adapter in failures, instead of a line on stderr. The exit code is 1 on failure either way.

Do not run a live command against an external recipient without approval.

Adapter pages

See provider-specific environment and field rules.

Last updated on