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

推荐订阅源

Spread Privacy
Spread Privacy
P
Palo Alto Networks Blog
P
Proofpoint News Feed
AI
AI
Help Net Security
Help Net Security
S
Securelist
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cisco Blogs
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
T
Tenable Blog
H
Help Net Security
NISL@THU
NISL@THU
F
Fortinet All Blogs
博客园_首页
G
GRAHAM CLULEY
L
LINUX DO - 最新话题
P
Privacy International News Feed
G
Google Developers Blog
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
The Register - Security
The Register - Security
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
Forbes - Security
Forbes - Security
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
D
Docker
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog

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
Send templated email with the Nylas Templates API
Qasim · 2026-06-25 · via DEV Community

Every app sends the same handful of emails over and over: the welcome message, the password reset, the follow-up, the receipt. The lazy way is to build each one as a string in your code, which means a copy change is a code change, marketing can't touch it, and the same wording drifts out of sync across three different send sites. Hosted templates fix that by pulling the copy out of your code into a named, reusable resource with variables you fill at send time.

This post covers templates from two angles: the HTTP API your backend calls, and the nylas CLI for quick sends from the terminal. One thing to get straight up front, which trips people up: the API's hosted templates and the CLI's templates are two different stores, and a later section spells out exactly how they differ. I work on the CLI, so the terminal commands below are the ones I reach for when testing.

What a hosted template is

A hosted template is a reusable email with a name, a subject, an HTML body, and variables, the placeholders you substitute with real values each time you send. You write {{name}} or {{topic}} in the subject or body, and at send time you supply a variables object that fills them in. The copy lives in one place, so changing the wording is one update rather than a hunt through your codebase.

Hosted templates come in two scopes. Application-level templates live at /v3/templates and are shared across your whole application; grant-level templates live at /v3/grants/{grant_id}/templates and belong to one connected account. This post uses application-level templates, which is the common case for shared copy, and the two work the same way apart from the path and who can see them. Either way, a template is shared infrastructure for outbound copy, not a draft that lives in one specific mailbox.

Create a hosted template

Creating a template is a POST /v3/templates with a name, subject, and body, where the subject and body can include {{variable}} placeholders. The body is HTML, so a branded message with formatting and links lives in the template the same way a plain one does. The response returns the template with its ID, which you use to send, render, or update it later.

curl --request POST \
  --url "https://api.us.nylas.com/v3/templates" \
  --header "Authorization: Bearer <NYLAS_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Follow-up",
    "subject": "Following up on {{topic}}",
    "body": "<p>Hi {{name}},</p><p>Wanted to follow up on {{topic}}.</p><p>Best,<br>{{sender}}</p>",
    "engine": "mustache"
  }'

The engine is mustache, the templating engine that interprets the {{variable}} syntax. Because the body is HTML, write it as HTML rather than plain text with newlines, and let the markup carry the structure. The variables work in both the subject and the body, so a single template can personalize the line a recipient sees in their inbox list as well as the message itself.

Send from a hosted template

Once a template exists, sending from it means referencing it on a POST /v3/grants/{grant_id}/messages/send request. You add a template object with the template's id and a variables map that fills the placeholders, and Nylas renders the final subject and body before the message goes out. The send still runs through the grant's own mailbox, so the message lands in the recipient's inbox as ordinary mail from that account, not anything that reads as auto-generated.

curl --request POST \
  --url "https://api.us.nylas.com/v3/grants/<GRANT_ID>/messages/send" \
  --header "Authorization: Bearer <NYLAS_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{
    "to": [{ "email": "client@example.com" }],
    "template": {
      "id": "<TEMPLATE_ID>",
      "variables": { "name": "Alex", "topic": "the proposal", "sender": "Sam" }
    }
  }'

The template only shapes the content; delivery is the same send path as a hand-written message. Because the template is referenced by a stable ID, your application code holds just that ID, not the copy, so the wording can change underneath it without a deploy.

From the terminal, nylas email send sends a hosted template directly: pass --template-id and the variables as --template-data JSON. The --template-scope flag (app or grant, defaulting to app) and --template-grant-id pick which of the two scopes the template lives in. This is the CLI surface for the same hosted templates, distinct from the local templates command covered later.

nylas email send \
  --to client@example.com \
  --template-id <TEMPLATE_ID> \
  --template-data '{ "name": "Alex", "topic": "the proposal", "sender": "Sam" }'

Missing variables: strict is the default

A template is only as good as the data you feed it, and the failure mode is an email that goes out with a raw {{name}} still in the body because you forgot a variable. The template object's strict flag guards against this, and the important detail is that strict is on by default: if the template contains a variable you didn't provide in variables, the send returns an error rather than delivering a half-filled message.

That default is the safe one, so most of the time you do nothing and a missing variable fails loudly in development instead of reaching a customer. You opt out by setting strict to false, which tells Nylas to render an unprovided variable as an empty string and send anyway. Reach for strict: false only when a blank is genuinely acceptable, like an optional middle name, and leave the default in place everywhere else. On the CLI it's the --template-strict flag on nylas email send, which also defaults to on.

Preview before you send

Sending a template to a real recipient just to see how it renders is a bad way to find a typo, so render it first. POST /v3/templates/{template_id}/render returns the rendered subject and body with your variables substituted, without sending anything, so you can show a preview in your own UI or assert on it in a test.

curl --request POST \
  --url "https://api.us.nylas.com/v3/templates/<TEMPLATE_ID>/render" \
  --header "Authorization: Bearer <NYLAS_API_KEY>" \
  --header "Content-Type: application/json" \
  --data '{ "variables": { "name": "Alex", "topic": "the proposal" } }'

Previewing is the step that catches an unfilled placeholder or a misspelled variable name before a customer ever sees it, and it costs nothing to run. Because the render returns both the subject and the HTML body, you get exactly what the send would produce, which makes it safe to drop straight into a preview pane.

The CLI previews the same way with --render-only on a send. It renders the hosted template with your data and prints the result instead of delivering it:

nylas email send --to client@example.com --template-id <TEMPLATE_ID> \
  --template-data '{ "name": "Alex", "topic": "the proposal" }' --render-only

Override a template per send

Sometimes a single send needs to differ from the template, a one-off subject line or a tweaked body for one recipient, without creating a whole new template. The send request handles this by letting the body and subject fields override the template's versions. If you pass a subject alongside a template, the send uses your subject instead of the template's, and the same goes for the body.

This keeps your template library from sprawling into near-duplicates. When most of a message matches an existing template and only the subject changes for one campaign, you reference the template for the shared body and override the subject inline, rather than cloning the template just to change one line. The template stays the canonical version, and the override is scoped to the single send that needs it.

Feed templates into workflows

Hosted templates pair with workflows, which send a templated message automatically when an event fires. An application-level workflow listens for a trigger, like a booking.created event, and sends a template you've defined to the relevant user, with no code running on your side at send time. The template supplies the copy and variables; the workflow supplies the trigger and the timing.

This is how you wire up transactional mail that should just happen on its own: a booking confirmation, a signup welcome, a status-change notice. You author the template once, attach it to a workflow that watches for the event, and Nylas sends it when the event occurs. The same template you'd use for a manual send becomes the payload of an automated one, so the copy stays consistent whether a person or a trigger sent it.

Manage your hosted templates

Templates accumulate, so the rest of the lifecycle is the usual CRUD against /v3/templates. A GET lists every template on your application, GET /v3/templates/{template_id} fetches one, PUT updates a template's name, subject, or body, and DELETE removes it. Updating is how a copy change propagates: edit the template once, and every future send that references it picks up the new wording, which is the entire point of pulling the copy out of your code.

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

Edit a template and the change is live for the next send that uses it, with no deploy on your side. That decoupling, copy in the template and logic in your app, is the reason to reach for hosted templates instead of inlining the string in three different send sites.

The CLI's templates are separate and local

Here's the part that surprises people. The CLI's nylas email templates commands do not manage the hosted templates above. They manage their own local templates, stored on your machine in ~/.config/nylas/templates.json, which are a terminal convenience and are not synced to the Nylas API. A template you create with nylas email templates create lives on your laptop, and a template you create with POST /v3/templates lives in the API; they're two separate stores that happen to share a name.

# This creates and uses a LOCAL CLI template, not an API-hosted one
nylas email templates create --name "Follow-up" --subject "Re: {{topic}}" \
  --body "Hi {{name}}, following up on {{topic}}." --category sales
nylas email templates use <local-template-id> --to client@example.com --var name=Alex

So nylas email templates create, list, show, update, delete, and use all operate on those local files, and the CLI-only --category flag and --var substitution apply there. It's genuinely handy for firing a quick personalized send from the terminal, but don't expect templates use to send an API-hosted template by its API ID. When you want a hosted template from the terminal, that's nylas email send --template-id <id> with --template-data, shown earlier, which is the CLI surface for the API's hosted templates rather than this local store.

Things to keep in mind

A short list of practices keeps templated email maintainable.

  • Hosted and CLI templates are different stores. Hosted API templates live at /v3/templates (or /v3/grants/{grant_id}/templates); the CLI email templates group is local files in ~/.config. Don't cross the IDs.
  • strict is on by default. A missing variable fails the send loudly; set strict: false only when an empty value is acceptable.
  • Preview before sending. The render endpoint expands the subject and body so you catch typos and unfilled placeholders for free.
  • Write the body as HTML. Hosted template bodies are HTML, so use markup rather than plain text with newlines.
  • Override inline instead of cloning. Pass subject or body on the send to vary one message without spawning a near-duplicate template.

Wrapping up

Hosted templates move your email copy out of code and into a reusable resource with variables you fill at send time. Create one with POST /v3/templates, send from it by passing a template object with variables on a send, and preview with the render endpoint before anything reaches a recipient. Strict is on by default so a missing variable fails loudly, you can override subject or body for one-offs, and editing the template once changes the wording everywhere it's used. Just remember the CLI's email templates are a separate local store, not these hosted ones.

Where to go next: