Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:
You can find your API keys in your SendPost Dashboard. Make sure to use your Sub-Account API Key for sending emails.

1. Install Dependencies

npm

2. Environment Setup

Create a .env file in your project root:

3. Basic Setup

Create app.js or server.js:
JavaScript

4. Create Email Service

Create services/emailService.js:
JavaScript

5. Send Your First Email

Simple Route Handler

JavaScript

6. Common Use Cases

Welcome Email Route

JavaScript

Password Reset Email

JavaScript

Order Confirmation Email

JavaScript

7. Using Middleware for Email Routes

Create middleware/emailValidation.js:
JavaScript
Use the middleware:
JavaScript

8. Error Handling Middleware

JavaScript

9. Batch Email Sending

JavaScript
Make sure your sender email domain is verified in your SendPost account before sending emails.

10. Next Steps

Explore more examples and use cases:

Express.js Documentation

Learn more about Express.js framework

SendPost JavaScript SDK

View the official SDK package on npm

Quickstart Example

View a complete working example on GitHub