Email Sending API
Two endpoints handle email delivery through different providers depending on whether AMP4Email is included.
POST /api/send-email
Non-AMP sending endpoint using Resend. Used by the AI Playground (when AMP is not enabled), Portfolio, Learn modules, Blog, and all other pages.
Request
curl -X POST https://kinetic.email/api/send-email \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Check out this kinetic email!",
"html": "<!DOCTYPE html>...",
"senderEmail": "sender@example.com"
}'
| Field | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Recipient email address |
subject | string | Yes | Email subject line |
html | string | Yes | Full HTML email content |
senderEmail | string | No | Sender's email (for attribution banner) |
Response
{
"success": true,
"message": "Email sent successfully!"
}
Processing Pipeline
Before sending, the endpoint applies several transformations:
- View in Browser URL — Replaces
{{VIB_URL}}withhttps://kinetic.email/view/{sendId}for the hosted email page - Tracking pixel injection — Replaces mail merge variables in tracking pixel URLs:
{{UUID}}— SHA-256 hash of recipient email (consistent across sends){{SEND_ID}}— Unique UUID for this specific send{{TIMESTAMP}}— Server-side epoch timestamp{{VIB_URL}}— Hosted View in Browser page URL
- Image URL resolution — Converts relative image paths to absolute
https://kinetic.email/...URLs - Attribution banner — If the sender is not the recipient, a "Sent via Kinetic Email" banner is appended
- XSS sanitization — Sender email is HTML-escaped before insertion into the banner
- Convex logging — Logs the send to
email_sendswith full HTML content for View in Browser retrieval
POST /api/send-email-mailgun
AMP4Email sending endpoint using Mailgun. Used by the AI Playground (when AMP is enabled) and the Station Sandbox.
Sends emails as raw MIME via Mailgun's messages.mime REST API, which supports the text/x-amp-html MIME part required for AMP4Email.
Request
curl -X POST https://kinetic.email/api/send-email-mailgun \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Interactive AMP email!",
"html": "<!DOCTYPE html>...",
"ampHtml": "<!doctype html><html ⚡4email>...",
"senderEmail": "sender@example.com",
"databaseId": "optional-workspace-id"
}'
| Field | Type | Required | Description |
|---|---|---|---|
to | string | Yes | Recipient email address |
subject | string | No | Email subject line (defaults to "Your Kinetic Email") |
html | string | Yes | Full HTML email content (fallback for non-AMP clients) |
ampHtml | string | No | AMP4Email HTML content |
senderEmail | string | Yes | Sender's email (for attribution + tracking) |
databaseId | string | No | Convex workspace ID for multi-tenant tracking |
Response
{
"success": true,
"message": "Email sent successfully via Mailgun!"
}
MIME Structure
When ampHtml is provided, the email is sent as multipart/alternative with three MIME parts:
multipart/alternative
├── text/plain (plain text fallback)
├── text/x-amp-html (AMP version — rendered in Gmail, Yahoo)
└── text/html (HTML fallback — rendered in all other clients)
When no ampHtml is provided, the same MIME structure is used without the AMP part.
Processing Pipeline
Same as /api/send-email plus:
- Suppression check — Checks
email_suppressionsandemail_bounce_logtables before sending - AMP HTML processing — Relative URLs resolved, tracking placeholders replaced in AMP content
- Raw MIME assembly — Builds RFC 2822 compliant MIME message
- Convex logging — Logs send event to real-time tracking database
POST /api/mailgun-webhook
Webhook endpoint for Mailgun delivery events. Not called directly — Mailgun POSTs to this endpoint when delivery events occur.
Events Handled
| Event | Action |
|---|---|
delivered | Logged to email_delivery_events |
failed (permanent) | Logged + recipient added to email_suppressions |
failed (temporary) | Logged to email_bounce_log with escalation (4+ = permanent suppress) |
complained | Logged + recipient permanently suppressed |
opened | Logged to email_delivery_events |
clicked | Logged to email_delivery_events |
All events trigger Telegram alerts for bounces and complaints.
Webhook Verification
If MAILGUN_WEBHOOK_SIGNING_KEY is set, the endpoint verifies the HMAC-SHA256 signature on every request using Mailgun's timestamp + token signing scheme.
Token Cost
Both send endpoints charge the email_send token action. The cost is defined in the token_action_costs table.
Error Handling
| Status | Error | Cause |
|---|---|---|
| 401 | Authentication required | Missing or invalid JWT |
| 402 | Insufficient tokens | Not enough tokens for email_send |
| 400 | Missing required fields | to or html not provided |
| 400 | Recipient suppressed | Recipient is on the suppression list |
| 500 | Send failed | Resend/Mailgun API error |