Quick setup examples
Vercel Functions
Send your first email from a Vercel Function using the sendping SDK.
Send your first email from a Vercel Function using the sendping Node SDK. The SDK works in both the Node.js and Edge runtimes. Install it with npm install sendping.
Prerequisites
Before you start, you will need:
- A SendPing API key.
- A verified domain to send from.
- The Vercel CLI installed.
1. Install the SDK
npm install sendping2. Set up environment variables
Add your API key to .env.local for local development. Never hardcode the key in source.
.env.local
SENDPING_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 { SendPing } from 'sendping';
const mb = new SendPing(process.env.SENDPING_API_KEY);
export async function POST() {
const { data, error } = await mb.emails.send({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@test.sendping.co'],
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 SENDPING_API_KEY environment variable in your Vercel project settings. Open https://your-project.vercel.app/api/send to send an email.
vercelOnly call the SendPing 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.