• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
dcm31

dcm31

gmail-drafts-template

Create Gmail drafts via Apps Script
Public
Like
gmail-drafts-template
Home
Code
3
README.md
appscript.ts
H
main.ts
Environment variables
Branches
1
Pull requests
Remixes
History
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.
Sign up now
Code
/
README.md
Code
/
README.md
Search
2/4/2026
Viewing readonly version of main branch: v1
View latest version
README.md

Gmail Drafts API

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.

How It Works

Your App → Val Town HTTP Endpoint → Google Apps Script → Gmail Draft
  1. Val Town exposes an HTTP endpoint that accepts draft requests
  2. Google Apps Script runs in your Google account with Gmail permissions
  3. Drafts appear in your Gmail, ready for review and sending

Setup

Step 1: Deploy the Apps Script

  1. Go to script.google.com and create a new project
  2. Copy the contents of appscript.ts into the editor
  3. Click Deploy → New deployment
  4. Select Web app as the type
  5. Set "Execute as" to Me and "Who has access" to Anyone
  6. Click Deploy and copy the web app URL

Step 2: Configure Val Town

  1. Fork this val to your account
  2. Add an environment variable:
    • Key: APPS_SCRIPT_URL
    • Value: Your Apps Script web app URL from Step 1

Step 3: Test It

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>!" }'

API Reference

POST /draft

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" }

GET /

Health check endpoint.

Response:

{ "status": "Gmail Drafts API ready", "endpoints": ["POST /draft"] }

Email Body Tips

  • 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

Files

FilePurpose
main.tsHTTP endpoint (Val Town)
appscript.tsGoogle Apps Script code (copy to script.google.com)

Security Notes

  • 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

License

MIT

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.