Send transactional email through the Resend API with a caller token.
About this template
This Neon Function sends transactional email through the Resend API.
Scaffold it
npm install -g neon@latestneon loginneon linkneon functions new resend-email
The CLI writes functions/resendemail/index.ts, declares the function in neon.ts, and adds the three environment variables to .env.example.
Configure Resend
Create an API key at resend.com/api-keys and verify a sending domain. For a quick test, you can send from onboarding@resend.dev, but Resend only delivers mail from that sender to the account owner's address.
Add the values to .env.local without replacing the Neon values already there:
API key from resend.com/api-keys with permission to send email.
RESEND_FROM
Verified sender address, for example Acme <hello@example.com>.
RESEND_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.
Run locally
neon dev
Call the URL that neon dev prints (the default is http://localhost:8787/). Send an email:
curl -s http://localhost:8787/send \ -H "authorization: Bearer $RESEND_FUNCTION_TOKEN" \ -H 'content-type: application/json' \ -d '{ "to": "you@example.com", "subject": "Hello from Neon", "text": "This was sent by a Neon Function." }'
{ "id": "4ef9a417-02e9-4d39-ad75-9611e0fcc33c" }
The body takes html, text, or both. to can be a string or an array of up to 50 addresses, and replyTo is optional.
Routes
Method
Path
Auth
Body
Result
GET
/
None
None
The function name and route list
POST
/send
Bearer RESEND_FUNCTION_TOKEN
{ to, subject, html?, text?, replyTo? }
200 with the Resend message id, or an error
to is a string or an array of up to 50 addresses. The subject can be up to 200 characters on one line, and html and text can be up to 100,000 characters each. A missing or shorter-than-32-character RESEND_FUNCTION_TOKEN returns 503, a wrong token returns 401, a malformed body returns 400, a body over 500,000 bytes returns 413, and any other path or method returns 404 or 405.
Deploy
neon deploy --env .env.localneon functions get resendemail
neon functions get prints the function's public URL, which you can test with curl:
curl -s https://<function-url>/send \ -H "authorization: Bearer $RESEND_FUNCTION_TOKEN" \ -H 'content-type: application/json' \ -d '{ "to": "you@example.com", "subject": "Hello from Neon", "text": "This was sent by a Neon Function." }'
Replace <function-url> with the URL from neon functions get resendemail.
Notes
RESEND_FUNCTION_TOKEN is required and must be at least 32 characters. If it is unset or too short, the function returns 503, and a wrong token returns 401.
The function caps input at 50 recipients, a 200-character subject, and 100,000 characters each for html and text.
The function returns 503 when RESEND_API_KEY, RESEND_FROM, or a 32+ character RESEND_FUNCTION_TOKEN is missing, 401 for a wrong token, and 502 when Resend rejects the message or the API is unavailable.
Resend's sandbox sender onboarding@resend.dev only delivers to the account owner. Use a verified domain for real recipients.