惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
小众软件
小众软件
有赞技术团队
有赞技术团队
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
AWS News Blog
AWS News Blog
C
Cisco Blogs
美团技术团队
T
Threat Research - Cisco Blogs
C
CERT Recently Published Vulnerability Notes
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
W
WeLiveSecurity
D
DataBreaches.Net
博客园 - 司徒正美
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Vercel News
Vercel News
月光博客
月光博客
T
Tailwind CSS Blog
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
V2EX
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
Recent Announcements
Recent Announcements

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Manage email drafts with the Nylas API and CLI
Qasim · 2026-06-23 · via DEV Community

Sometimes an email shouldn't go out the instant your code runs. A human needs to review it first, or the user wants to compose now and hit send later, or an AI agent proposes a reply that a person approves before it ships. The mechanism for all three is the same: a draft. Build that against providers directly and you're juggling Gmail's draft resource, Microsoft Graph's, and an IMAP APPEND to the Drafts folder, each with its own shape and quirks.

The Nylas Email API collapses that into one draft resource. You create a draft on the user's account, it lands in their real Drafts folder, and you send it later with a single request, the same way across Gmail, Microsoft 365, Yahoo, iCloud, IMAP, and Exchange. This post walks the full draft lifecycle from two angles: the HTTP API for your backend, and the nylas CLI for the terminal. I work on the CLI, so the terminal commands below are the ones I reach for.

One draft resource across every provider

A draft in the Nylas model is a real object in the user's mailbox, not a staging area on the side. When you create one, it saves to the user's own Drafts folder on their provider, so it shows up in their normal mail client exactly like a draft they started themselves. That's the property that makes drafts useful for review workflows: a person can open the mailbox and see the pending message before it sends.

Because drafts are real provider objects, edits flow both ways. A draft you create through the API appears in the user's mail client within the provider's sync window, and a change the user makes there alters the same draft you'd fetch back through the API. The operations split across two paths: create and list live on /v3/grants/{grant_id}/drafts, while fetch, update, send, and delete act on a specific draft at /v3/grants/{grant_id}/drafts/{draft_id}. They behave the same across all six providers, so you write the integration once.

Create a draft

Creating a draft is a POST /v3/grants/{grant_id}/drafts with the same message fields you'd use for a send: to, cc, bcc, subject, body, and optional reply_to and tracking_options. Nylas saves it to the user's Drafts folder and returns a draft object with an id you use to update, send, or delete it later. The request below creates a draft with recipients and a body:

curl --request POST \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/drafts" \
  --header "Authorization: Bearer <NYLAS_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{
    "subject": "Proposal for next quarter",
    "body": "Hi, here is the draft proposal for your review.",
    "to": [{ "email": "client@example.com" }]
  }'

The CLI wraps this in nylas email drafts create, which takes the message as flags. --to (-t), --subject (-s), and --body (-b) are the core ones, with --cc, --reply-to, --attach (-a) for a file, and --signature-id for a stored signature available on top. It's the quickest way to drop a draft into a mailbox and confirm it appears in the user's client:

nylas email drafts create \
  --to client@example.com \
  --subject "Proposal for next quarter" \
  --body "Hi, here is the draft proposal for your review."

The create command accepts a grant ID as an optional argument and otherwise uses your default account, so a quick nylas email drafts create -t client@example.com -s "Hi" -b "Draft body" drops a draft into the connected mailbox in one line.

List and fetch saved drafts

Before sending or editing, you often need to see what's already saved. GET /v3/grants/{grant_id}/drafts lists every draft on the account, and GET /v3/grants/{grant_id}/drafts/{draft_id} returns a single one with its full body and recipients. This is how an approval UI loads pending messages for a reviewer, or how your app confirms a draft was created before showing a send button.

curl --request GET \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/drafts" \
  --header "Authorization: Bearer <NYLAS_API_KEY>"

From the terminal, nylas email drafts list prints the saved drafts and nylas email drafts list --json returns the raw objects for scripting. Fetch one with nylas email drafts show <draft-id>. Because drafts are real provider objects, the list includes drafts the user started in their own mail client, not only the ones your app created.

Update a draft before it sends

A draft isn't frozen once created. PUT /v3/grants/{grant_id}/drafts/{draft_id} updates it, which is what you'd call when a reviewer edits the message or your app revises a proposed reply. There's one behavior to internalize: the update replaces the draft's fields rather than patching them, so you send the full set of recipients and the complete body each time, not just the parts that changed.

curl --request PUT \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/drafts/<DRAFT_ID>" \
  --header "Authorization: Bearer <NYLAS_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{
    "subject": "Proposal for next quarter (revised)",
    "body": "Hi, here is the revised proposal with the updated numbers.",
    "to": [{ "email": "client@example.com" }]
  }'

Because the update is a full replace, treat the draft in your application as the source of truth and re-send its entire state on every change. Updating is API-only: the nylas email drafts command group covers create, list, show, send, and delete, but not update, so revisions go through PUT from your backend. This replace-not-patch behavior is the single most common mistake with the drafts API: send only the changed field and you'll wipe the recipients or body you left out.

Send a draft

Sending is a POST /v3/grants/{grant_id}/drafts/{draft_id} against the draft's own path. Nylas dispatches it through the user's provider, removes it from the Drafts folder, and files the sent copy in the Sent folder, exactly as if the user had clicked send in their mail client. There's no separate send endpoint that needs the message fields again; the POST to the draft's own path is the send.

curl --request POST \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/drafts/<DRAFT_ID>" \
  --header "Authorization: Bearer <NYLAS_API_KEY>"

From the CLI that's nylas email drafts send <draft-id>. Any tracking_options you set when creating the draft still apply when it sends on a connected account, so open and click tracking carries through from draft to delivery. One scoped exception: on Agent Accounts, sending through the drafts endpoint doesn't fire open or click tracking, so if you need tracking on an Agent Account message, send it directly with POST /messages/send and tracking_options instead of drafting it first.

Discard a draft

When a draft is abandoned, DELETE /v3/grants/{grant_id}/drafts/{draft_id} removes it. Because the draft is a real provider object, the delete also removes it from the user's Drafts folder, keeping the mailbox and your application in sync rather than leaving an orphaned draft behind in the user's client.

curl --request DELETE \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/drafts/<DRAFT_ID>" \
  --header "Authorization: Bearer <NYLAS_API_KEY>"

The CLI command is nylas email drafts delete <draft-id>. Reach for delete when a user cancels a queued message or a review step rejects a proposed reply, so the draft doesn't linger in the mailbox suggesting an email is still pending.

The human-in-the-loop pattern

Drafts are the natural fit for any flow where a message needs approval before it goes out, and that's increasingly an AI-agent flow. The pattern is three steps: the agent generates a draft with POST /drafts, a human reviews it (in your app's UI or directly in the mailbox, since the draft is a real provider object), and on approval you send it by ID with POST /drafts/{draft_id}. Nothing leaves the mailbox until that final call.

This beats having the agent send directly for any message where a mistake is costly. A drafted reply sits in the Drafts folder where a person can catch a wrong recipient, a hallucinated detail, or an inappropriate tone before it reaches the customer. If the reviewer edits the message, you PUT the changes; if they reject it, you DELETE it; if they approve, you POST to send. The whole approval loop maps cleanly onto the four draft operations.

Draft first, or send directly?

Both drafting and a direct POST /messages/send put a message in the user's mailbox, so when is the extra step worth it? Draft when a message needs to exist before it's sent: for human review, for a compose-now-send-later experience, or to let a user open and edit it in their own mail client first. Send directly when the message is ready and nothing stands between composing it and delivering it.

There's a small cost to drafting. It's two API calls instead of one, and the draft occupies the user's Drafts folder until it sends or you delete it. For transactional mail generated and sent in the same step, that overhead buys you nothing, so send directly. For anything a person or a policy has to approve, the draft's place in the real mailbox is the entire point, and the two-call cost is what gives you a safe place to pause.

Attach files to a draft

Drafts carry attachments the same way sends do, and the encoding depends on size. For files that keep the whole request under 3 MB, pass them inline as Base64 in the JSON body, which keeps creating the draft a single call. That 3 MB ceiling covers the message body and the attachments together, so a draft with a couple of small documents is fine inline.

Above 3 MB, switch from JSON to a multipart/form-data request, which providers cap at 25 MB for the full message. The practical rule is simple: a small PDF or image goes inline as Base64, while a larger file uses multipart. From the CLI, nylas email drafts create --attach ./proposal.pdf (or -a) handles the encoding for you. For attachments beyond 25 MB there's a separate large-attachments flow, a Microsoft-only path that uploads the file first (up to 150 MB) and references it by ID.

Whichever path you use, the attachment becomes part of the draft and travels with it. When you later send the draft with POST /drafts/{draft_id}, the files go out with the message; you don't re-attach anything at send time. That's another reason the draft is a clean review primitive: a reviewer opening the draft in their mail client sees the exact attachments that will ship, not a separate list to cross-check. If a reviewer removes or swaps a file, update the draft with PUT so the saved object matches what will actually send.

Things to keep in mind

A few behaviors separate a smooth drafts integration from one that surprises you.

  • Update is a full replace, not a patch. Send the complete recipient list and body on every PUT, or you'll drop the fields you omit.
  • Sending is a POST to the draft itself. You don't re-send the message fields; the POST /drafts/{draft_id} dispatches the saved draft.
  • Drafts are real provider objects. Edits a user makes in their mail client change the same draft, and your delete removes it from their Drafts folder too.
  • Mind the 3 MB inline payload limit. Larger attachments use a multipart/form-data request, capped at 25 MB by the provider, not inline Base64.
  • Drafts are the approval primitive. For agent flows, draft then send-by-ID gives you a clean place for human review before anything ships.

Wrapping up

Drafts give you a save-and-review step that works identically across every provider Nylas connects. Create with POST /drafts, revise with a full-replace PUT, send with a POST to the draft's own path, and discard with DELETE. The CLI's nylas email drafts mirrors all of these except update, which stays on the API. Because each draft is a real object in the user's mailbox, the pattern doubles as a human-in-the-loop approval gate, which is exactly what an AI agent needs before it sends on someone's behalf.

Where to go next: