Public
Likegmail-drafts-template
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: v1View latest version
A simple API that creates Gmail drafts via Google Apps Script. Perfect for automating outreach, notifications, or any workflow that needs to queue up emails for review before sending.
Your App → Val Town HTTP Endpoint → Google Apps Script → Gmail Draft
- Val Town exposes an HTTP endpoint that accepts draft requests
- Google Apps Script runs in your Google account with Gmail permissions
- Drafts appear in your Gmail, ready for review and sending
- Go to script.google.com and create a new project
- Copy the contents of
appscript.tsinto the editor - Click Deploy → New deployment
- Select Web app as the type
- Set "Execute as" to Me and "Who has access" to Anyone
- Click Deploy and copy the web app URL
- Fork this val to your account
- Add an environment variable:
- Key:
APPS_SCRIPT_URL - Value: Your Apps Script web app URL from Step 1
- Key:
curl -X POST https://YOUR-VAL-ENDPOINT/draft \ -H "Content-Type: application/json" \ -d '{ "recipient": "test@example.com", "subject": "Hello from the API", "body": "This is a <b>test draft</b>!" }'
Create a new Gmail draft.
Request Body:
{ "recipient": "user@example.com", "subject": "Email subject", "body": "HTML body content with <b>formatting</b>", "cc": "optional@example.com" }
Response:
{ "status": "success", "message": "Draft created successfully", "draftId": "r1234567890" }
Health check endpoint.
Response:
{ "status": "Gmail Drafts API ready", "endpoints": ["POST /draft"] }
- Use
<br>for line breaks (not\n) - Full HTML is supported:
<b>,<i>,<a href="">,<ul>, etc. - The plain text version is auto-generated by stripping HTML tags
| File | Purpose |
|---|---|
main.ts | HTTP endpoint (Val Town) |
appscript.ts | Google Apps Script code (copy to script.google.com) |
- The Apps Script runs with your Gmail permissions
- Anyone with the Val Town endpoint URL can create drafts in your account
- Consider adding authentication if exposing publicly
- Drafts are only created—never sent automatically
MIT