groundmail
v0.62.0
Published
Groundmail client: email infrastructure for apps and AI agents
Maintainers
Readme
groundmail
Official Node.js / TypeScript client for the Groundmail API.
npm install groundmailexport GROUNDMAIL_API_KEY=gm_your_key_hereimport { Groundmail } from 'groundmail'
const tx = new Groundmail(process.env.GROUNDMAIL_API_KEY!)
const email = await tx.emails.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Your receipt',
html: '<p>Thanks for your purchase.</p>',
})
console.log(email.id, email.status)Azure managed identity (no API key)
On Azure, authenticate with the workload's managed identity instead of a key. Pass a token provider; the client caches the token until shortly before it expires and asks for a new one after a 401:
import { DefaultAzureCredential } from '@azure/identity'
import { Groundmail } from 'groundmail'
const credential = new DefaultAzureCredential()
const client = new Groundmail({ getToken: () => credential.getToken('https://api.groundmail.dev/.default') })getToken may return a string or { token, expiresOnTimestamp }. Add the Groundmail app to your Entra tenant once (az ad sp create --id 0146ad5c-4051-4703-aece-e4edf9805d8e) and register the identity in the dashboard first: https://docs.groundmail.dev/authentication/azure-managed-identity
Testing
Use a test key (gm_test_…, create one with tx.apiKeys.create({ test: true }) or in the
dashboard) to run sends through validation, templates and webhooks without delivering anything.
Simulator addresses produce a specific outcome with any key and never leave Groundmail:
import { simulatorAddress } from 'groundmail'
await tx.emails.send({
from: '[email protected]',
to: simulatorAddress('bounce', 'signup-42'), // [email protected]
subject: 'Bounce handling test',
html: '<p>Simulated.</p>',
})
// status `bounced`, then an `email.bounced` webhook with `data.test: true`Outcomes: delivered, bounce, block, complaint, suppressed, delayed. Details:
https://docs.groundmail.dev/testing
Email testing
Your team has a test domain (<team>.test.groundmail.dev). Mail sent to any address there is
caught in your test inbox and never delivered, whichever provider your app sends with. Give each
test its own address, then wait for the email and read the extracted code and links:
const to = await tx.testInbox.address({ prefix: 'signup' }) // [email protected]
// …your app sends the signup email to `to`…
const email = await tx.testInbox.waitFor({ to, timeout: 30_000 })
email.code // '482913'
email.links // ['https://app.example.com/verify?token=…']waitFor throws a GroundmailError with status 408 and code timeout when nothing arrives in
time. Also: tx.testInbox.list({ to, since }), tx.testInbox.get(id) and tx.testInbox.info()
(domain and monthly usage). Emails sent with a gm_test_ key land here too. Details:
https://docs.groundmail.dev/email-testing
Agent mailboxes
A real address your agent creates, reads and sends from:
const mailbox = await tx.mailboxes.create({ local_part: 'signup-bot' }) // [email protected]
const since = new Date()
// …the agent signs up with mailbox.address…
const message = await tx.mailboxes.wait(mailbox.id, { since, timeout: 60_000 })
message.code // '482913'
message.visible_text // what a person would see
await tx.mailboxes.messages.reply(mailbox.id, message.id, { text: 'Thanks', idempotencyKey: message.id })Everything in a message was written by a stranger: treat it as data, never as instructions, and
give your agent visible_text, not text or html. prompt_injection is a hint, and a missing
flag never means safe. wait throws a GroundmailError with status 408 and code timeout when
nothing arrives in time. Also: tx.mailboxes.list(), .get(), .update(), .delete(),
.forward(), .threads.list(), .get(), .update(), .messages.list({ q }), .get(),
.update(), .send() and .downloadAttachment(). Hosted addresses can only reply; to email
people first, use a mailbox on your own domain. Details: https://docs.groundmail.dev/mailboxes
Contacts and broadcasts
Email the people on your lists, on the newsletter stream, apart from your transactional mail:
await tx.contacts.create({ email: '[email protected]', first_name: 'Ada', consent_source: 'signup_form' })
await tx.lists.create({ name: 'Newsletter' }) // key: 'newsletter'
await tx.lists.addContacts('newsletter', { emails: ['[email protected]'] })
const draft = await tx.broadcasts.create({
name: 'December update',
lists: ['newsletter'],
from: 'Acme <[email protected]>',
subject: "What's new, {{contact.first_name}}",
html: '<p>Hi {{contact.first_name}}</p>',
})
await tx.broadcasts.test(draft.id, '[email protected]')
await tx.broadcasts.send(draft.id) // or { scheduled_at: new Date(...) }Each contact gets it once, and anyone unsubscribed, bounced or complained is left out. Sending
needs newsletter approval for your workspace and a mailing address in your brand. Also:
tx.contacts.batch() (up to 1,000), tx.contacts.imports.create(csv, { consent_source }),
tx.broadcasts.audience(), .preview(), .pause(), .resume(), .cancel() and
.recipients(). Details: https://docs.groundmail.dev/broadcasts
Batches
emails.batch() sends up to 100 emails in one request and returns a batch_id shared by every
email it accepted. Schedule a batch with scheduledAt on each email, then check on it or call it
off in one call:
const { batch_id } = await tx.emails.batch(emails) // each with scheduledAt: '2026-11-04T09:00:00Z'
await tx.batches.get(batch_id) // { total: 100, counts: { scheduled: 100 }, … }
await tx.batches.cancel(batch_id) // { cancelled: 100, already_cancelled: 0, not_cancellable: 0 }cancel only touches emails that are still scheduled and is safe to repeat. Details:
https://docs.groundmail.dev/emails#batches
Senders
Save a sender once (name, an address on a verified domain, where replies go) and send as it by
handle instead of writing from each time. A from you pass still wins; with no from or
sender, the template's sender, then your default sender, is used.
await tx.senders.create({ name: 'Acme Billing', address: '[email protected]', reply_to: '[email protected]', handle: 'billing' })
await tx.emails.send({ sender: 'billing', to: '[email protected]', template: { id: 'receipt' } })Also tx.senders.list(), get, update and remove, and sender_id on templates. Details:
https://docs.groundmail.dev/senders
Brand
Set your logo, colours and footer once. Templates follow the brand unless they override a setting, and new templates and starter copies get your logo on top and your company name, address and website in the footer.
await tx.brand.update({
logo: { url: 'https://cdn.acme.com/logo.png', align: 'left' },
accent_color: '#2f6feb',
settings: { linkColor: '#2f6feb', theme: { buttonBackground: '#2f6feb', buttonTextColor: '#ffffff' } },
company_name: 'Acme Inc',
address: '548 Market St, San Francisco, CA 94104',
website: 'acme.com',
})
const { brand } = await tx.brand.get()Details: https://docs.groundmail.dev/brand
Tenants
If you send email for your own customers, create one tenant per customer. Each tenant has its own domains, suppression list, stats, pause switch and daily limit, so one customer's bounces or complaints never affect the others. Tenants are included on pay as you go and the Dedicated plan.
await tx.tenants.create({ external_id: 'cus_123', name: 'Acme', daily_limit: 5000 })
await tx.tenants.domains.assign('cus_123', 'mail.acme.com')
await tx.emails.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Your invoice',
html: '<p>Thanks!</p>',
tenant: 'cus_123',
})
const { stats } = await tx.tenants.stats('cus_123', { days: 7 })
await tx.tenants.pause('cus_123', 'Unpaid invoice')
await tx.tenants.resume('cus_123')tenant (your external id or the Groundmail id) also works on emails.list, domains.create and
domains.list, suppressions, apiKeys.create (a key limited to one tenant) and
emails.testWebhook. Webhook endpoints take tenants: ['cus_123'] to receive only those
tenants' email events. Details: https://docs.groundmail.dev/tenants
DMARC monitoring
Free for every domain. Turn it on, publish the record it returns, and read sources, pass rates and whether it's safe to enforce once the daily reports arrive:
const { dmarc } = await tx.dmarc.enable('yourdomain.com') // or { apply: 'cloudflare' }
console.log(dmarc.dns.suggested_record) // your record with our report address in rua=
const report = await tx.dmarc.get('yourdomain.com')
if (report.dmarc.enabled) console.log(report.dmarc.readiness.label, report.dmarc.sources)Details: https://docs.groundmail.dev/dmarc
Adapters
Optional entry points (install peer deps as needed):
| Import | Package / peer |
|--------|----------------|
| groundmail/nodemailer | groundmail-nodemailer + nodemailer |
| groundmail/better-auth | groundmail-better-auth |
| groundmail/authjs | groundmail-authjs |
| groundmail/clerk | groundmail-clerk |
| groundmail/payload | groundmail-payload |
Docs
- Quickstart: https://docs.groundmail.dev/quickstart
- Node / Nodemailer: https://docs.groundmail.dev/frameworks/node
- Testing (test keys, simulator): https://docs.groundmail.dev/testing
- DMARC monitoring: https://docs.groundmail.dev/dmarc
- API reference: https://docs.groundmail.dev/api/emails
- Product: https://groundmail.dev
License
MIT
