emailSender
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v5View latest version
HTTP endpoint called by the agentcr Cloudflare Worker to send outbound reply emails via Val Town's built-in email service.
EmailRoutingAgent (Cloudflare Durable Object)
│ POST { secret, to, subject, text }
▼
emailSender (this val — HTTP export)
│ validates shared secret
│ calls Val Town std/email
▼
Reply email delivered to original sender
This val exists because Cloudflare Workers cannot send outbound emails directly without a verified sender domain on Cloudflare Email Routing. Val Town's std/email library handles delivery without any DNS setup.
POST to this val's endpoint with a JSON body:
{ "secret": "your-shared-secret", "to": "customer@example.com", "subject": "Re: Your enquiry", "text": "Plain-text reply body..." }
All four fields are required. The secret must match the EMAIL_SECRET environment variable.
{ "ok": true }
On error:
{ "ok": false, "error": "error message" }
- Requests without a valid
secretreturn401 Unauthorized - The secret is never logged
- The endpoint only accepts
POST(OPTIONS for CORS preflight)
Set in Val Town → Project Settings → Environment Variables:
| Variable | Description |
|---|---|
EMAIL_SECRET | Shared secret — must match EMAIL_INBOUND_SECRET on the Cloudflare Worker |
The worker calls this val via the VALTOWN_SEND_URL secret:
npx wrangler secret put VALTOWN_SEND_URL # this val's endpoint URL
The endpoint URL is shown in Val Town under the val's Endpoints tab.
emailInboundHandler— receives inbound emails and forwards to the Cloudflare Worker