Quick setup examples
Vercel Functions
Send your first email from a Vercel Function using the mailblastr SDK.
Send your first email from a Vercel Function using the mailblastr Node SDK. The SDK works in both the Node.js and Edge runtimes. Install it with npm install mailblastr.
Prerequisites
Before you start, you will need:
- A MailBlastr API key.
- A verified domain to send from.
- The Vercel CLI installed.
1. Install the SDK
npm install mailblastr2. Set up environment variables
Add your API key to .env.local for local development. Never hardcode the key in source.
.env.local
MAILBLASTR_API_KEY=mb_xxxxxxxxx3. Create the function
Create a route file under app/api/send/route.ts if you are using the Next.js App Router.
app/api/send/route.ts
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);
export async function POST() {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@example.com'],
subject: 'hello world',
html: '<strong>it works!</strong>',
});
return Response.json(error ? { error } : { data }, {
status: error ? 500 : 200,
});
}4. Send email locally
Run the function locally and open the endpoint URL to send an email at http://localhost:3000/api/send.
npm run dev5. Send email in production
Deploy with the Vercel CLI, then add your MAILBLASTR_API_KEY environment variable in your Vercel project settings. Open https://your-project.vercel.app/api/send to send an email.
vercelOnly call the MailBlastr API from server-side code (Route Handlers, Server Actions, API routes). Never ship your API key to the browser.
See the full request body in the Send an email reference.