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 or update your .env.local file:

3. Send Your First Email

Using API Routes (App Router)

Create app/api/send-email/route.ts:
TypeScript

Using Server Actions (App Router)

Create app/actions/sendEmail.ts:
TypeScript

4. Common Use Cases

Welcome Email

Create app/actions/welcomeEmail.ts:
TypeScript

Password Reset Email

Create app/actions/passwordReset.ts:
TypeScript

Order Confirmation Email

Create app/actions/orderConfirmation.ts:
TypeScript

5. Using in React Components

Contact Form Example

Create app/components/ContactForm.tsx:
TypeScript

6. Error Handling & Best Practices

Create a Reusable Email Service

Create lib/sendpost.ts:
TypeScript
Make sure your sender email domain is verified in your SendPost account before sending emails.

7. Next Steps

Explore more examples and use cases:

Next.js Documentation

Learn more about Next.js App Router and Server Actions

SendPost JavaScript SDK

View the official SDK package on npm

Quickstart Example

Complete working example from this quickstart guide