Install the SDK
npm install groundmailSet your API key
export GROUNDMAIL_API_KEY=gm_your_key_hereIn Vercel or Kubernetes, store the same value as an environment variable instead of committing it to the repo.
Send from an API route
Create app/api/send-welcome/route.ts:
import { NextResponse } from 'next/server'
import { Groundmail } from 'groundmail'
const tx = new Groundmail(process.env.GROUNDMAIL_API_KEY!)
export async function POST() {
const result = await tx.emails.send({
from: 'onboarding@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome to your app',
html: '<p>Your account is ready.</p>',
})
return NextResponse.json(result)
}React Email
Author components with React Email, then pass them to the SDK:
npm install @react-email/render reactawait tx.emails.send({
from: 'onboarding@yourdomain.com',
to: 'user@example.com',
subject: 'Welcome',
react: WelcomeEmail({ name: 'Ada' }),
})Full walkthrough: Send React Email.
v0
v0 generates Next.js apps, so the pattern above applies: send from a Route Handler (app/api/.../route.ts) or a Server Action.
- For local work, put
GROUNDMAIL_API_KEY=gm_…in.env.local. - In Vercel, open the project, then Settings, then Environment Variables, and add
GROUNDMAIL_API_KEYfor Production, Preview and Development. - Redeploy. Vercel only picks up a new variable on the next deployment.
Never give the key a NEXT_PUBLIC_ name: Next.js puts those variables in the browser bundle. Don't read it in a client component either.
To have v0 write the integration, paste the builder prompt with this as rule 6:
6. Send from a Route Handler (app/api/.../route.ts) or a Server Action, using the groundmail npm package. GROUNDMAIL_API_KEY is a server-only Vercel environment variable: never use a NEXT_PUBLIC_ name for it. Note in the README that GROUNDMAIL_API_KEY must be set in Vercel before deploying.Until your domain is verified, send from noreply@mail.groundmail.dev to your own Groundmail account email. To send to other people, verify your domain, add a payment method under Settings → Billing (the Free plan is not charged), set from to an address on your domain, and confirm GROUNDMAIL_API_KEY is set for Production in Vercel.