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
appscript.ts into the editorBefore the web app can create drafts, you need to authorize it to access your Gmail:
testCreateDraft functionNote: You only need to do this once. After granting permissions, the web app will be able to create drafts automatically.
APPS_SCRIPT_URLcurl -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"] }
<br> for line breaks (not \n)<b>, <i>, <a href="">, <ul>, etc.| File | Purpose |
|---|---|
main.ts | HTTP endpoint (Val Town) |
appscript.ts | Google Apps Script code (copy to script.google.com) |
MIT