Express
Use the Posthawk Node.js SDK with Express. Also works with Fastify, Hono, and Koa.
SDK
app.post("/send", ...)Send emails from an Express route handler.
Example
typescript
import express from 'express';
import { Posthawk } from 'posthawk';
const app = express();
app.use(express.json());
const posthawk = new Posthawk(process.env.POSTHAWK_API_KEY!);
app.post('/send', async (req, res) => {
const { data, error } = await posthawk.emails.send({
from: 'hello@yourdomain.com', ...req.body,
});
if (error) return res.status(error.statusCode || 500).json({ error: error.message });
res.json(data);
});
app.listen(3000);