Comprehensive examples for sending emails with Resend using Express (Node.js).
- Node.js 22+
- A Resend account
# Choose your variant
cd typescript # or javascript
# Install dependencies
npm install
# Copy environment variables
cp ../.env.example .env
# Add your Resend API key to .envcd typescript
npx tsx examples/basic-send.ts
npx tsx examples/batch-send.ts
npx tsx examples/with-attachments.ts
npx tsx examples/with-cid-attachments.ts
npx tsx examples/scheduled-send.ts
npx tsx examples/with-template.ts
npx tsx examples/prevent-threading.ts
npx tsx examples/audiences.ts
npx tsx examples/domains.ts
npx tsx examples/inbound.ts
npx tsx examples/double-optin-subscribe.ts [email protected] "John Doe"
npx tsx examples/double-optin-webhook.tscd javascript
node examples/basic-send.js
node examples/batch-send.js
node examples/with-attachments.js
node examples/with-cid-attachments.js
node examples/scheduled-send.js
node examples/with-template.js
node examples/prevent-threading.js
node examples/audiences.js
node examples/domains.js
node examples/inbound.js
node examples/double-optin-subscribe.js [email protected] "John Doe"
node examples/double-optin-webhook.jscd typescript
npm run dev
# Then in another terminal:
curl -X POST http://localhost:3000/send \
-H "Content-Type: application/json" \
-d '{"to": "[email protected]", "subject": "Hello", "message": "Hi from Express!"}'cd javascript
npm run dev
# Same curl commands workGET /health— Health checkPOST /send— Send an emailPOST /webhook— Handle Resend webhook eventsPOST /double-optin/subscribe— Subscribe with confirmationPOST /double-optin/webhook— Confirm subscription on click
import { Resend } from "resend";
const resend = new Resend("re_xxxxxxxxx");
const { data, error } = await resend.emails.send({
from: "Acme <[email protected]>",
to: ["[email protected]"],
subject: "Hello",
html: "<p>Hello World</p>",
});
console.log("Email ID:", data?.id);express-resend-examples/
├── typescript/
│ ├── examples/ # 12 standalone examples
│ ├── src/index.ts # Express app
│ ├── package.json
│ └── tsconfig.json
├── javascript/
│ ├── examples/ # 12 standalone examples
│ ├── src/index.js # Express app
│ └── package.json
├── .env.example
└── README.md
See something that could be improved? We welcome contributions! Open an issue to report a bug or suggest an improvement, or submit a pull request with your changes.
MIT