Venmail's official Node.js/TypeScript SDK for receiving webhook events, validating signatures, and normalizing delivery data.
@venmail/vsm gives your app everything it needs to trust Venmail webhook
traffic: an Express-ready middleware, signature utilities, TypeScript guards,
and helpers for keeping delivery timelines consistent across services.
- Drop-in Express middleware – verify HMAC signatures, parse payloads, and dispatch strongly typed events with a single handler.
- Security helpers – low-level utilities for shared-secret headers, raw body validation, and custom transports.
- Typed payload detection – quickly branch on inbound mail, delivery status, bounce, or form events.
- Delivery timeline normalization – convert the many Venmail payloads into
a single
NormalizedDeliveryEventbefore your business logic runs.
npm install @venmail/vsm
# or
yarn add @venmail/vsm
# or
pnpm add @venmail/vsmThe package ships as pure ESM with generated type definitions. Middleware helpers assume an Express-compatible runtime.
The SDK is built around the venmailIntegrationWebhook middleware. Drop it
into your Express app, pass your shared secret, and handle events in one place.
💡 Need email templates? Use our companion CLI tool
@venmail/vsm-clito scan your codebase and generate email templates automatically for your framework. Install withnpm install -g @venmail/vsm-cliand runvsm scanin your project.
import express from "express";
import {
venmailIntegrationWebhook,
type VenmailIntegrationEvent,
} from "@venmail/vsm";
const app = express();
app.use(express.json({ type: "application/json" }));
app.post(
"/webhooks/venmail",
venmailIntegrationWebhook({
secret: process.env.VENMAIL_WEBHOOK_SECRET!,
async onEvent(event) {
console.log("Received", event.event_type, event.payload);
},
})
);
app.listen(3000);Need to validate events outside of Express (e.g. edge runtimes or custom parsers)? Use the low-level helpers:
import { verifyVenmailSignature, verifySharedSecretHeader } from "@venmail/vsm";
const isSigned = verifyVenmailSignature({
secret: process.env.VENMAIL_WEBHOOK_SECRET!,
signature: req.get("x-venmail-signature") ?? "",
rawBody,
});
const hasSharedSecret = verifySharedSecretHeader({
secret: process.env.VENMAIL_WEBHOOK_SECRET!,
provided: req.get("X-Venmail-Webhook-Secret"),
});Venmail emits distinct payload shapes for inbound mail, status updates, bounces, and more. The guards make branching safe and ergonomic:
import {
detectVenmailWebhookKind,
isMailWebhookPayload,
normalizeDeliveryEvent,
} from "@venmail/vsm";
const kind = detectVenmailWebhookKind(req.body);
if (kind.kind === "mail" && isMailWebhookPayload(req.body)) {
// handle inbound email ingestion
}
if (
kind.kind === "status" ||
kind.kind === "bounce"
) {
const delivery = normalizeDeliveryEvent(req.body);
console.log(delivery.status, delivery.campaignId);
}| Helper | What it does |
|---|---|
venmailIntegrationWebhook(options) |
Express middleware that validates signatures, parses JSON, emits strongly typed events, and auto-responds if you don't write a response. |
verifyVenmailSignature(options) |
Low-level SHA-256 HMAC validation for webhook signatures. |
verifySharedSecretHeader(options) |
Constant-time comparison for shared-secret headers (e.g. X-Venmail-Webhook-Secret). |
detectVenmailWebhookKind(payload) |
Returns a discriminated union describing the payload category. |
isMailWebhookPayload, isStatusPayload, isBouncePayload |
Narrow specific payload shapes before operating on them. |
normalizeDeliveryEvent(payload) |
Converts payloads into a consistent { messageId, recipient, status, campaignId } object. |
All exported interfaces are re-exported from the package root for IDE autocompletion.
- Live docs: The GitHub Pages deployment lives at
https://venmail.github.io/vsm. Every push tomaintriggers.github/workflows/docs.yml, which runsnpm ci, executes thebuild:docsscript, and publishes the contents ofdocs-site/viaactions/deploy-pages. - Local preview: Run
npm run docs:serveto spin up a static server pointed atdocs-site/(defaults to http://localhost:8080). Update the files insidedocs-site/and re-runnpm run build:docsbefore pushing to guarantee CI has the latest assets.
Need help? Open an issue on GitHub with reproduction details plus any relevant request IDs from Venmail logs.
The SDK also ships an AgentClient for the Venmail Agent REST API — the
bearer-authenticated endpoints that let AI agents (Claude, MCP servers, any
HTTP client) read and send mail from a Venmail inbox.
Tokens are provisioned from the Venmail UI (Admin → AI Agents, or Profile →
Advanced → Share with AI agent) and look like ma-vm_<prefix>_<secret>.
import { AgentClient } from "@venmail/vsm";
const client = new AgentClient({
baseUrl: "https://mail.example.com",
token: process.env.VENMAIL_AGENT_TOKEN!,
// Called when a refreshed token arrives; persist it somewhere.
onTokenRefreshed: (t) => keychain.set("venmail:agent", t),
});
// Identify the bound inbox & scopes.
const me = await client.me();
// List threads.
const { data: threads, next_cursor } = await client.listThreads({
folder: "inbox",
limit: 25,
});
// Reply.
await client.replyToThread(threads[0].id, {
body: "Thanks — I'll follow up shortly.",
});
// Send a new message.
await client.sendMessage({
to: "alice@example.com",
subject: "Quick update",
body: "Hello Alice, here is the status.",
});
// Rotate the token.
await client.refreshToken();| Method | Scope | Description |
|---|---|---|
me() |
(any valid token) | Identity + scopes of the bound inbox. |
listThreads(params) |
inbox:read |
Paginated thread list with cursor + q. |
getThread(id) |
thread:read |
Full thread with nested messages. |
markThreadRead(id) |
mail:mark_read |
Idempotent. |
replyToThread(id, body) |
mail:send |
Inline reply to an existing thread. |
sendMessage(input) |
mail:send |
New outbound mail. |
refreshToken() |
(any valid token) | Rotates; old token is revoked server-side. |
revokeToken() |
(any valid token) | Explicit revoke. |
All API failures throw AgentApiError with a status field and the raw
server body. Transient 5xx failures are retried up to retries (default 2)
with jittered exponential backoff.
import { AgentApiError } from "@venmail/vsm";
try {
await client.listThreads();
} catch (e) {
if (e instanceof AgentApiError && e.status === 403) {
// Token missing required scope — reissue with the right permissions.
}
throw e;
}npm run typecheck
npm run buildThe dist/ artifacts are generated via tsc. No bundler is required.
MIT