This Neon Function sends email through AI Inbx.
About this template
Send an emailRecommended
POST an AI Inbx send request: from, to, subject, and html or text; optionally thread_id to follow up, scheduled_at to send later, or draft to hold it for review.
/send-email
Setup
neon functions new aiinbxIn the AI Inbx console, pick a plan on the Billing page under Settings, and create an API key with the sending scope.
echo "AI_INBX_API_KEY=..." >> .env.local
export AI_INBX_FUNCTION_TOKEN=$(openssl rand -hex 32)
echo "AI_INBX_FUNCTION_TOKEN=$AI_INBX_FUNCTION_TOKEN" >> .env.local
neon dev| Variable | Description | Required |
|---|---|---|
| AI_INBX_API_KEY | API key from aiinbx.com/app with the sending scope. Keep this server-side. | Yes |
| AI_INBX_FUNCTION_TOKEN | Random token (at least 32 characters, for example from openssl rand -hex 32) callers send as Authorization: Bearer <token>; required because Neon Function URLs are public. | Yes |
Send
curl -s http://localhost:8787/send-email \
-H "authorization: Bearer $AI_INBX_FUNCTION_TOKEN" \
-H 'content-type: application/json' \
-d '{
"from": "Ada <ada@acme.aiinbx.app>",
"to": "grace@example.com",
"subject": "Quick question",
"text": "Does Thursday still work for a call?"
}'{
"id": "eml_...",
"thread_id": "thr_...",
"status": "queued",
"scheduled_at": null,
"review_url": null,
"suppressed": [],
"pacing": null
}The function passes the body to AI Inbx unchanged, so it takes any field of an AI Inbx send request. It needs from, to, subject, and html, text, or both. It also takes optional fields such as attachments, unsubscribe headers, and tracking.
from must be an address on a domain the workspace sends from or a connected mailbox, and AI Inbx rejects any other sender. Every workspace can send from <slug>.aiinbx.app without DNS setup. To send from your own domain, verify it, and to send from a Gmail or Outlook account, connect it.
AI Inbx also takes these fields:
| Field | Effect |
|---|---|
thread_id | Follows up in an earlier email's thread and sets In-Reply-To and References. |
scheduled_at | Sends at an RFC 3339 time with an offset, up to 30 days ahead. |
draft: true | Holds the email instead of sending it and returns a review_url where a person can edit and send it. |
With an Idempotency-Key header, a retry that sends the same key returns the first email instead of sending a second one.
suppressed lists the recipients that a suppression list removed. AI Inbx sets pacing, with an estimated send time, when a sending limit or sending hours apply to the email.
The function passes AI Inbx errors through with their status, code, issues, and request_id. If AI Inbx rejects the API key, the function returns 502.
Deploy
neon deploy --env .env.local
neon functions get aiinbx







