Install bavimail, keep your API key in .env.local, and call client.emails.send() from an App Router route handler. The code below ran against the live Bavimail API on October 15, 2026, with bavimail 0.3.7 and Next.js 16.4.1. Bavimail email is live, with a free plan.
What you need
- A Bavimail account. Start free, no credit card.
- A verified domain with at least one address on it. See domains.
- An API key from the dashboard, and the id of the address you send from (find it).
- A Next.js app with the App Router.
1. Install the SDK and set your keys
npm install bavimailIn .env.local:
BAVIMAIL_API_KEY=your_api_key
BAVIMAIL_ALIAS_ID=your_alias_id2. Send from a route handler
The handler emails the signed-in user's own address, never an address from the request. A route that emails whatever address it's given lets anyone who finds it send mail from your account.
Create app/:
import { Bavimail } from 'bavimail'
import { getCurrentUser } from '@/lib/auth'
const client = new Bavimail({ apiKey: process.env.BAVIMAIL_API_KEY })
export async function POST() {
const user = await getCurrentUser()
if (!user) {
return Response.json({ error: 'Sign in first' }, { status: 401 })
}
const sent = await client.emails.send({
aliasId: process.env.BAVIMAIL_ALIAS_ID!,
toEmail: user.email,
subject: 'Welcome aboard',
body: '<p>Thanks for signing up.</p>',
})
return Response.json({ id: sent.id, status: sent.status })
}getCurrentUser stands for your auth library's session lookup. It returns the signed-in user, or null.
Call it from your app once the user has signed in, for example right after sign-up:
await fetch('/api/welcome', { method: 'POST' })It returns the email id and queued. Without a signed-in user it returns a 401 and sends nothing. The route runs on the server, so the key never reaches the browser. Also limit how often one user can call it, so a single account can't use up your daily sending.
3. Check delivery
client.emails.get(id) returns the email with its status. In our test the email was delivered within 6 seconds of being sent. To act on delivery, bounces or replies as they happen, use webhooks.
What it costs
The free plan sends 6,000 emails a month, at most 200 a day, with no card. Developer is US$5 a month for 50,000 emails (pricing).
- Free6,000
- Developer$5 a month50,000
- Startup$50 a month300,000
- Scale$500 a month2,500,000
The same steps in Python are in Send email with Python.
