Guide · Tools
How to send email with cURL
Send an email from the command line with a single cURL request. Handy for testing your setup or sending from shell scripts and cron jobs.
Last reviewed November 2026
1. Set up
You need a Stack Emails API key (create one free) and a verified sending domain.
export STACKEMAILS_API_KEY=se_live_xxxxxxxxxxxx
2. Send your first email
curl -X POST https://stackemails.com/v1/emails \
-H "Authorization: Bearer $STACKEMAILS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "Acme <hello@mail.acme.com>",
"to": "ada@example.com",
"subject": "Hello from the command line",
"text": "It works!"
}'
A successful request returns 202 with the message id, for example { "id": "msg_5b1f0c6c2a8e4e0f", "status": "queued" }. Errors return a JSON body with error.code and error.message (see errors).
Send to several recipients
"to" accepts an array: "to": ["ada@example.com", "grace@example.com"]. Each recipient sees the full To list; for separate messages use the batch endpoint.
Retry safely
Add -H "Idempotency-Key: nightly-report-2026-11-05" so a retried cron job never sends twice.
Production checklist
- Keep the API key in an environment variable or secret manager, never in client-side code.
- Add an
Idempotency-Keyheader to retries so a timeout never sends twice (idempotency). - Subscribe to webhooks for bounces and complaints.
- Check your domain's SPF, DKIM and DMARC records.
- Start from a tested email template for password resets, receipts and invites.