All guides

Send Email from Koa

Send emails from Koa middleware and routes

1. Install the SDK

npm install sendpigeon

2. Set your API key

Add your SendPigeon API key to your environment variables:

SENDPIGEON_API_KEY=your_api_key_here

Get your API key from the dashboard.

3. Send your first email

import Koa from "koa";
import Router from "@koa/router";
import bodyParser from "koa-bodyparser";
import { SendPigeon } from "sendpigeon";

const app = new Koa();
const router = new Router();
const client = new SendPigeon(process.env.SENDPIGEON_API_KEY!);

router.post("/contact", async (ctx) => {
  const { email, name } = ctx.request.body as { email: string; name: string };

  await client.emails.send({
    from: "hello@yourdomain.com",
    to: email,
    subject: `Thanks for reaching out, ${name}!`,
    html: `<h1>We got your message</h1><p>We'll get back to you soon.</p>`,
  });

  ctx.body = { success: true };
});

app.use(bodyParser());
app.use(router.routes());
app.listen(3000);

Features

  • Async/await native
  • Middleware-based
  • Lightweight and modular

Ready to send emails?

Get started with 1,000 free emails per month.

Start for free