Loading...
Loading...
Send an email to a mailing list via the SchemaVaults mail-server `/api/send` route, using either the `sendEmailToMailingList()` helper or the `schemavaults-send-email send-to-mailing-list` CLI from `@schemavaults/send-email`. Use when any server-side TypeScript/JavaScript code needs to send a notification to a mailing list audience — **or when Claude Code itself wants to send a one-shot notification at the end of a task** (preferred — invoke the CLI via `bunx schemavaults-send-email send-to-mailing-list …`; fallback — write a short script to `/tmp/` and run it with `bun`).
npx skill4agent add schemavaults/send-email send-email-to-mailing-list@schemavaults/send-emailsendEmailToMailingList()POST /api/send.claude/skills/sendEmail()bun add @schemavaults/send-email
# or: npm install @schemavaults/send-emailSCHEMAVAULTS_MAIL_API_KEYapi_keyssvlts_mail_pk_SCHEMAVAULTS_MAILING_LIST_IDMAILING_LISTSError("Failed to load ... from environment variable ...")SCHEMAVAULTS_APP_ENVIRONMENT"production""development""staging"productiontemplate_idlistEmailTemplates()@schemavaults/send-emaillist-email-templatesimport { sendEmailToMailingList } from "@schemavaults/send-email";
export async function notifyMailingListOfSignup(userName: string): Promise<void> {
await sendEmailToMailingList({
body: {
subject: `New signup: ${userName}`,
message: {
template_id: "<template-id-from-GET-/api/templates>",
template_props: {
/* prop shape per the template's description field */
},
},
},
});
}texthtmltexthtmlimport { sendEmailToMailingList } from "@schemavaults/send-email";
export async function notifyMailingListOfError(err: Error, context: string): Promise<void> {
const subject = `[alert] ${context}: ${err.message}`;
const text =
`An error occurred in ${context}.\n\n` +
`Message: ${err.message}\n\n` +
`Stack:\n${err.stack ?? "(no stack)"}\n`;
const html =
`<p>An error occurred in <code>${context}</code>.</p>` +
`<p><strong>Message:</strong> ${err.message}</p>` +
`<pre>${err.stack ?? "(no stack)"}</pre>`;
await sendEmailToMailingList({
body: { subject, message: { text, html } },
});
}html<>&sendEmailToMailingListSCHEMAVAULTS_MAILING_LIST_IDawait sendEmailToMailingList({
mailingListId: "00000000-0000-0000-0000-000000000000",
body: {
subject: "Hello from a specific list",
message: { text: "Hello", html: "<p>Hello</p>" },
},
});@schemavaults/send-emailschemavaults-send-emailbash/tmp/bun run# Raw text/html (both required)
bunx schemavaults-send-email send-to-mailing-list \
--subject "[ops] nightly backup finished" \
--text "Backup completed at $(date -u +%FT%TZ). 0 errors." \
--html "<p>Backup completed at $(date -u +%FT%TZ). <strong>0 errors.</strong></p>"
# Template-based
bunx schemavaults-send-email send-to-mailing-list \
--subject "Welcome aboard, Alice" \
--template-id welcome-email \
--template-props '{"name":"Alice"}'
# Override the mailing list per-call
bunx schemavaults-send-email send-to-mailing-list \
--mailing-list-id 00000000-0000-0000-0000-000000000000 \
--subject "..." --text "..." --html "..."
# Long bodies: read from files instead of inline strings
bunx schemavaults-send-email send-to-mailing-list \
--subject "weekly digest" \
--text-file /tmp/digest.txt \
--html-file /tmp/digest.html
# Or supply the entire request body as a JSON file (validated server-side)
bunx schemavaults-send-email send-to-mailing-list --body-file /tmp/payload.jsonnpxbunxbunSCHEMAVAULTS_MAIL_API_KEYSCHEMAVAULTS_MAILING_LIST_ID0bunx schemavaults-send-email send-to-mailing-list --help--dry-run--dry-runtemplate_propsbunx schemavaults-send-email send-to-mailing-list --dry-run \
--subject "Welcome aboard, Alice" \
--template-id welcome-email \
--template-props '{"name":"Alice"}'[dry-run] mailing-list request validated; no email sent.0@schemavaults/send-emailbunx schemavaults-send-email send-to-mailing-list \
--subject "[claude-code] workflow finished: <short description>" \
--text "$(printf 'Claude just finished a workflow.\n\nSummary:\n- <bullet 1>\n- <bullet 2>\n- <bullet 3>\n')" \
--html "$(printf '<p>Claude just finished a workflow.</p><p><strong>Summary:</strong></p><ul><li><bullet 1></li><li><bullet 2></li><li><bullet 3></li></ul>')"<short description>/tmp/// /tmp/send-notification-after-workflow.ts
import { sendEmailToMailingList } from "@schemavaults/send-email";
async function main(): Promise<void> {
await sendEmailToMailingList({
body: {
subject: "[claude-code] workflow finished: <short description>",
message: {
text:
"Claude just finished a workflow.\n\n" +
"Summary:\n" +
"- <bullet 1>\n" +
"- <bullet 2>\n" +
"- <bullet 3>\n",
html:
"<p>Claude just finished a workflow.</p>" +
"<p><strong>Summary:</strong></p>" +
"<ul>" +
"<li><bullet 1></li>" +
"<li><bullet 2></li>" +
"<li><bullet 3></li>" +
"</ul>",
},
},
});
console.log("[notify] sent");
}
main().catch((err) => {
console.error("[notify] failed:", err);
process.exit(1);
});@schemavaults/send-emailnode_modules/bun run /tmp/send-notification-after-workflow.tsSCHEMAVAULTS_MAIL_API_KEYSCHEMAVAULTS_MAILING_LIST_ID--dry-rundryRun: truetemplate_propssendEmailToMailingListOmit<SendEmailRequestBody, "to" | "cc" | "bcc">toccbcctype MailingListNotificationBody = {
subject: string;
message:
| { template_id: string; template_props?: unknown }
| { text: string; html: string };
from?: string; // defaults to the mail-server's configured sender
replyTo?: string; // optional reply-to override
dryRun?: boolean; // server validates without dispatching
};
// Full call signature:
type ISendEmailToMailingListOpts = {
body: MailingListNotificationBody;
mailingListId?: string; // override SCHEMAVAULTS_MAILING_LIST_ID
bearerToken?: string; // override SCHEMAVAULTS_MAIL_API_KEY; rarely needed
mailServerUrl?: string; // override the server origin; rarely needed
environment?: "production" | "development" | "staging";
dryRun?: boolean; // convenience; sets body.dryRun
};try/catchtry {
await sendEmailToMailingList({
body: {
subject: `New signup: ${userName}`,
message: { text, html },
},
});
} catch (notifyErr) {
console.error("[notify] failed to send mailing list notification", notifyErr);
}| Error | Cause |
|---|---|
| Env var not set (or empty string) in the runtime environment. |
| Env var not set (or empty string) in the runtime environment. |
| Your |
| |
| The API key is allowlisted to a different mailing list than the one targeted. |
| Server-side Zod parsing failed; usually a template |
productionawait sendEmailToMailingList({
environment: "development",
body: {
subject: "dev smoke test",
message: { template_id: "my-test-email", template_props: { name: "test" } },
},
});SCHEMAVAULTS_APP_ENVIRONMENTgetAppEnvironment()@schemavaults/app-definitionsopts.environment.claude/skills/bun add @schemavaults/send-email.env.localSCHEMAVAULTS_MAIL_API_KEY=svlts_mail_pk_...
SCHEMAVAULTS_MAILING_LIST_ID=00000000-0000-0000-0000-000000000000node_modules/@schemavaults/send-email/dist/send-email-to-mailing-list.{d.ts,js}sendEmailToMailingList()ISendEmailToMailingListOptssend-email.{d.ts,js}sendEmail()getSchemaVaultsMailApiKey()send-email-request-body-schema.{d.ts,js}createSendEmailRequestBodySchemaindex.d.ts