Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elastic Email examples for developers and AI agents

Real-world examples for building with the Elastic Email API, SMTP, webhooks and AI coding agents.

Quick Start · SMTP · AI Agents · API Docs · Get an API Key · Verify Your Domain

Latest release License GitHub stars Open issues 24 stacks Elastic Email API v4 AI agent ready

Production-shaped code samples for the Elastic Email email API and SMTP relay, in 24 languages, frameworks and serverless platforms. Every stack implements the same use cases through the official SDKs and REST API v4, so what you learn in one maps directly to the others.

import {
  Configuration,
  EmailsApi,
} from "@elasticemail/elasticemail-client-ts-axios";

const emailsApi = new EmailsApi(
  new Configuration({
    apiKey: process.env.ELASTICEMAIL_API_KEY,
  })
);

await emailsApi.emailsTransactionalPost({
  Recipients: { To: ["you@yourdomain.com"] },
  Content: {
    From: process.env.EMAIL_FROM!, // must be on a domain verified in Elastic Email
    Subject: "Hello from Elastic Email",
    Body: [
      { ContentType: "HTML", Content: "<p>Hello!</p>" },
      { ContentType: "PlainText", Content: "Hello!" },
    ],
  },
});

Start building

Pick your stack and send your first email in about five minutes.

Stack Quick start
Next.js Quick start
Express Quick start
Python Quick start
PHP Quick start
Laravel Quick start
.NET Quick start
Go Quick start
Java Quick start

Something else? Ruby, Rust, Elixir, Kotlin, plain Node.js, NestJS, Fastify, Hono, Bun, the full-stack JavaScript frameworks, serverless platforms, SMTP, email templates, AI agents and background jobs are all in All stacks.

What is included

Every example runs on the free plan - see plans and pricing.

Using with AI agents

The repository includes support for Claude Code, agent skills, MCP and LLM-readable documentation.

npx skills add ElasticEmail/elasticemail-examples

These examples are laid out so a coding agent can find the right file and copy working code into your project instead of guessing at the API.

File For
AGENTS.md Agents working in this repo: layout, conventions, the webhook and sender-domain rules that are easy to get wrong. Claude Code reads it through CLAUDE.md.
skills/elasticemail/SKILL.md An Agent Skill that adds Elastic Email to an existing project: detect the stack, copy the matching example, set env vars.
examples.json Machine-readable map from each use case to its source files, for every stack.
llms.txt / llms-full.txt Index of every guide and quickstart, and the same content in one file.

Install the skill in Claude Code:

/plugin marketplace add ElasticEmail/elasticemail-examples
/plugin install elasticemail@elasticemail

For other agents that support skills, copy skills/elasticemail/ into the agent's skills folder (for example .cursor/skills/ or ~/.codex/skills/), or use the npx skills add command above.

Give the agent API access with the Elastic Email MCP server. It sends email and manages contacts, lists, segments, templates, domains, suppressions and campaigns. It is hosted at https://mcp.elasticemail.com, nothing to install; it takes your API key in the X-Auth-Token header:

# Claude Code
claude mcp add --transport http elasticemail https://mcp.elasticemail.com --header "X-Auth-Token: $ELASTICEMAIL_API_KEY"
// Cursor: ~/.cursor/mcp.json
{ "mcpServers": { "elasticemail": { "url": "https://mcp.elasticemail.com", "headers": { "X-Auth-Token": "<api key>" } } } }

// VS Code: .vscode/mcp.json
{ "servers": { "elasticemail": { "type": "http", "url": "https://mcp.elasticemail.com", "headers": { "X-Auth-Token": "<api key>" } } } }

The full tool list and setup docs are at elasticemail.com/mcp.

All stacks

Each quickstart is five minutes from nothing to a delivered email; the folder it links to covers every example and route for that language.

Language Five-minute quickstart All examples Frameworks
Next.js Send email with Next.js TypeScript / JavaScript Next.js 15, React 19
PHP Send email with PHP PHP examples Slim, Symfony
Laravel Send email with Laravel Laravel examples Laravel 11
Python Send email with Python Python examples Flask, FastAPI, Django
Ruby Send email with Ruby Ruby examples Sinatra, Rails
Go Send email with Go Go examples Chi, Gin
Java Send email with Java Java examples Javalin, Spring Boot
Kotlin Send email with Kotlin Kotlin examples Ktor 3
.NET (C#) Send email with .NET .NET examples ASP.NET Minimal APIs, ASP.NET MVC
Rust Send email with Rust Rust examples Axum
Elixir Send email with Elixir Elixir examples Phoenix
Node.js Send email with Node.js Node.js examples node:http, no framework
Express Send email with Express Express examples Express 5
NestJS Send email with NestJS NestJS examples (TypeScript) NestJS 11
Fastify Send email with Fastify Fastify examples Fastify 5
Hono Send email with Hono Hono examples Hono
Bun Send email with Bun Bun examples Bun.serve()
Remix Send email with Remix Remix examples Remix 2
Nuxt Send email with Nuxt Nuxt examples Nuxt 3
SvelteKit Send email with SvelteKit SvelteKit examples SvelteKit 2
Astro Send email with Astro Astro examples Astro 5
RedwoodJS Send email with RedwoodJS RedwoodJS examples RedwoodJS 8
TanStack Start Send email with TanStack Start TanStack Start examples TanStack Start
Serverless Send email from serverless All 12 platforms Cloudflare Workers, Vercel, Supabase Edge, AWS Lambda, Deno Deploy, Netlify, Railway, Encore, Firebase, Azure Functions, Cloud Run, Convex
SMTP Send your first email with SMTP All 28 integrations Auth0, Supabase, Keycloak, WordPress, Ghost, Strapi, GitLab, Grafana, n8n, Nodemailer, Laravel, Django, Rails and more
Email templates Send your first templated email Template examples React Email, MJML
AI agents Send your first email from an AI agent AI agent examples Vercel AI SDK, LangChain, OpenAI Agents SDK
Background jobs Send your first email from a background job Queue examples BullMQ, Inngest, Trigger.dev

JavaScript and TypeScript stacks use @elasticemail/elasticemail-client-ts-axios. Other languages use the matching Elastic Email SDK. Elixir calls the REST API directly with Req. All stacks are pinned to the 4.2 SDK line and target REST API v4.

Send with SMTP

Some tools only let you enter an SMTP server: Auth0, Supabase Auth, Keycloak, WordPress, Ghost, Grafana. Some apps already send through their framework's mailer. For both, smtp-elasticemail-examples/ shows how to point them at smtp.elasticemail.com, with no SDK involved. The SMTP quickstart sends a first message with curl.

Platforms Code
Auth: Auth0, Supabase, Keycloak, Firebase Auth, Appwrite, PocketBase
CMS: WordPress, Ghost, Strapi, Directus, Payload, Liferay
Self-hosted: GitLab, Grafana, Nextcloud, Discourse, Metabase, Retool
Automation: n8n, Zapier, Customer.io
Node.js, Nodemailer, NextAuth, PHPMailer, Laravel, Django, Rails

SMTP uses its own credentials (Settings > SMTP in the dashboard), not the API key.

Examples Included

Every language and framework stack covers the sending, webhook, inbound, contacts, double opt-in and domain examples. The full-stack framework apps (Next.js, Remix, Nuxt, SvelteKit, Astro, RedwoodJS, TanStack Start, Laravel) skip some account-level ones, and the serverless folders focus on send and webhooks. examples.json lists exactly which files cover which use case in each stack.

Sending

  • Basic Send - HTML and plain text transactional email
  • Batch Send - One bulk call with per-recipient merge fields
  • With Attachments - Base64 file attachments
  • With CID Attachments - Inline images referenced by Content-ID
  • With Templates - Hosted templates with merge variables (created on first run)
  • Scheduled Send - Delayed delivery with TimeOffset
  • Prevent Threading - Unique X-Entity-Ref-ID header per message
  • Email Status - Look up a transaction and view a sent message

Receiving

  • Webhooks - Create webhooks and handle Sent, Opened, Clicked, Error, AbuseReport and Unsubscribed events
  • Inbound - Inbound routes that push parsed email to your endpoint

Contacts and lists

  • Contacts - Lists, contact CRUD, custom fields
  • Double Opt-in - Confirmation link with an HMAC token, or confirmation through the Clicked event
  • Suppressions - Unsubscribe, bounce and complaint lists

Account

  • Domains - Add a sending domain and read SPF, DKIM, MX, DMARC and tracking status
  • Statistics - Account-level delivery statistics
  • Email Verification - Single address verification
  • Sub-accounts - List sub-accounts, and optionally create one and assign credits

Guides

Language-neutral explanations of the concepts every example uses. Start with the quickstart for your stack, come here when you need the detail.

Guide What it covers
Environment variables Every variable, where it is used, what breaks without it
Sending email Transactional vs bulk, merge fields, scheduling, threading, delivery lookup
Attachments File attachments and inline (CID) images
Templates Hosted templates, merge values, creating one from code
Contacts and lists Lists, contact CRUD, statuses, custom fields
Double opt-in Both confirmation flows, and when to pick which
Webhooks Events, their parameters, the token scheme, handler design
Inbound email Routes, MX setup, the parsed fields you receive
Suppressions Unsubscribes, bounces, complaints
Domains and deliverability SPF, DKIM, MX, DMARC, tracking, warm-up
Account Statistics, email verification, sub-accounts
Error handling The error body, and how each SDK surfaces it
API map Use case to SDK method, in every language here
Troubleshooting Symptom to cause, for the failures that actually happen

Getting Started

  1. Get an API key from app.elasticemail.com. Copy it straight away - it is shown once. API settings covers creating and managing keys.

  2. Verify a sender domain in the Elastic Email dashboard. Examples send from EMAIL_FROM, which must belong to a verified domain. Publishing the SPF and DKIM records takes a few minutes - How to verify your domain walks through it.

  3. Clone this repository:

    git clone https://github.com/ElasticEmail/elasticemail-examples.git
  4. Choose your stack and follow its README

  5. Copy .env.example to .env and fill in ELASTICEMAIL_API_KEY, EMAIL_FROM and EMAIL_TO

  6. Run the examples

Notes on webhooks and inbound

Elastic Email does not sign webhook requests. Every example appends a shared secret to the callback URL (?token=ELASTICEMAIL_WEBHOOK_TOKEN) and verifies it with a constant-time compare. Elastic Email sends each event as a GET request with the details in the query string (status, to, transaction, messageid, category, target). Inbound email is different: it arrives as a POST with form fields (from_email, subject, body_text, body_html, att1_name, att1_content, ...).

When you save a webhook, Elastic Email sends one test event to the URL and saves the webhook only if it gets a 2xx response, so the URL has to be publicly reachable at that moment. During local development, run a tunnel such as ngrok and set PUBLIC_URL accordingly. The test event carries sample values (to=test@test.com, messageid=abc1234). The handlers accept it like any other event; in your own app, skip it before it reaches your data.

Full detail: Webhooks and Inbound email.

Resources

Contributing

Found a problem or want to add a stack? Open an issue or send a pull request. CONTRIBUTING.md covers the conventions and how to add a stack. To report a security issue, see SECURITY.md. Not sure where a question belongs? See SUPPORT.md. Participation is governed by the Code of Conduct.

License

MIT

About

Real-world Elastic Email examples for transactional email, SMTP, webhooks, inbound email, contacts, serverless platforms and AI coding agents across 20+ languages and frameworks.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

22 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages