A Next.js app that sends a transactional welcome email via the Brew SDK every time a user signs up.
- User fills out the signup form (email, first name, last name)
- Their contact is upserted into Brew with
source: "signup" - A pre-made welcome email is sent to their inbox instantly via Brew
npm install- API key: Go to brew.new/settings/api and create an API key.
- Welcome email: Go to brew.new and create a welcome email. Once it exists, click into that specific email template — the URL will look like
https://brew.new/emails/<emailId>. Copy the<emailId>segment from the URL; that is the value you'll use forBREW_WELCOME_EMAIL_ID. If you ever swap the welcome email for a different template, repeat this step and update the value in both.env.localand Vercel → Settings → Environment Variables, then redeploy. - Sending domain: Go to brew.new settings and verify a sending domain — copy its
domainId.
BREW_API_KEY=brew_your_key_here
BREW_WELCOME_EMAIL_ID=your_email_id_here
BREW_DOMAIN_ID=your_domain_id_here
- Go to brew.new → Audience → New Audience
- Set filter:
sourceequalssignup - Save as "Signups"
- All signup form submissions will appear here automatically
npm run dev- Push to GitHub and import in Vercel
- Add the three env vars in Vercel → Settings → Environment Variables (the same values from
.env.local, including theBREW_WELCOME_EMAIL_IDyou copied from the email template URL) - Redeploy so the new env vars are picked up (env var changes do not apply to existing deployments)
- If you later change the welcome email template, update
BREW_WELCOME_EMAIL_IDin both.env.localand the Vercel dashboard, then redeploy
/— Signup form/admin— Shows your domains, emails, contact count, and audiences/admin/contacts— Full contact list with verification status
If you want Brew to AI-generate a fresh welcome email for every signup instead of using a pre-made one, replace the sends flow in src/app/api/signup/route.ts with:
const generated = await brew.emails.generate({
prompt: `Create a warm friendly welcome email for ${firstName} ${lastName} who just signed up. Use the brand's design and tone. Include a welcome message and a get started CTA.`,
})
if (!('emailId' in generated)) {
return NextResponse.json(
{ error: 'Email generation failed' },
{ status: 500 }
)
}
await brew.sends.create({
emailId: generated.emailId,
domainId: process.env.BREW_DOMAIN_ID!,
subject: `Welcome, ${firstName}!`,
emails: [email],
})Note: This approach costs Brew credits per signup and adds 30–90 seconds to the signup response (per the SDK's documented agent runtime). Recommended for low-volume or personalized flows only. Remove BREW_WELCOME_EMAIL_ID from your env vars if using this approach, and set export const maxDuration = 300 in the route so Vercel's serverless timeout doesn't kill the request mid-generation.