Send Emails with Express
Learn how to send transactional emails using PostStack and Express.
1. Install the SDK
bash
npm install @poststack/sdk express2. Initialize the client
typescript
import PostStack from '@poststack/sdk';
import express from 'express';
const poststack = new PostStack(process.env.POSTSTACK_API_KEY!);
const app = express();
app.use(express.json());3. Send an email
typescript
app.post('/send', async (req, res) => {
const { to, subject, html } = req.body;
const { data, error } = await poststack.emails.send({
from: 'hello@yourdomain.com',
to,
subject,
html,
});
if (error) return res.status(400).json({ error });
res.json(data);
});
app.listen(3000, () => console.log('Server running on port 3000'));Ready to send emails with Express?
Create a free account and get your API key in under a minute.