Wraps Logo
Quickstart / Express

Send Email from Express

Deploy email infrastructure and send your first email from an Express application.

Prerequisites

Before you begin, make sure you have:

  • Node.js 18 or later installed
  • AWS credentials configured (AWS Setup Guide)
  • A domain you own

1
Deploy Infrastructure

Run the Wraps CLI to deploy email infrastructure to your AWS account:

GNU Bashterminal.sh
npx @wraps.dev/cli email init

2
Add Your Domain

Add and verify your sending domain with AWS SES:

GNU Bashterminal.sh
npx @wraps.dev/cli email domains add -d yourdomain.com

DNS Setup

The CLI will output DKIM records to add to your DNS provider. Once added, verify them with npx @wraps.dev/cli email domains verify -d yourdomain.com

3
Install the SDK

Install the @wraps.dev/email package in your Express project:

GNU Bashterminal.sh
npm install @wraps.dev/email

4
Create Email Service

Create a singleton email service that reuses AWS connections across requests:

TypeScriptsrc/services/email.ts
import { WrapsEmail } from '@wraps.dev/email';// Create a singleton instance — reuses AWS connectionsexport const email = new WrapsEmail({  region: process.env.AWS_REGION || 'us-east-1',});

5
Add a Send Route

Create an Express route that accepts email parameters and sends using the SDK:

TypeScriptsrc/routes/email.ts
import { Router } from 'express';import { email } from '../services/email';const router = Router();router.post('/send', async (req, res, next) => {  try {    const { to, subject, html } = req.body;    const result = await email.send({      from: 'hello@yourdomain.com',      to,      subject,      html,    });    res.json({ success: true, messageId: result.messageId });  } catch (error) {    next(error);  }});export default router;

6
Error Handling Middleware

Add error handling middleware to return meaningful error responses for email failures:

TypeScriptsrc/middleware/error-handler.ts
import { SESError, ValidationError } from '@wraps.dev/email';export function emailErrorHandler(err, req, res, next) {  if (err instanceof ValidationError) {    return res.status(400).json({ error: err.message, field: err.field });  }  if (err instanceof SESError) {    const status = err.retryable ? 503 : 400;    return res.status(status).json({ error: err.message, code: err.code });  }  next(err);}

Error Types

  • ValidationError — Invalid email parameters (missing fields, bad format)
  • SESError — AWS SES errors (throttling, bounces, invalid identity)

Next Steps

Email SDK Reference

Learn about all available methods, options, and advanced features.

View SDK Docs
Error Codes

Reference for all error codes and troubleshooting steps.

View Errors

Need Help?

If you run into any issues, check our GitHub discussions or open an issue.

Get Help