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.
Security Note: Never expose your SendPost API key in client-side React code. Always use a backend API endpoint to send emails. The examples below show both approaches, but prefer the backend approach for production.

1. Install Dependencies

npm

2. Create Email Service Hook

Create hooks/useEmail.js:
JavaScript

3. Contact Form Component

Create components/ContactForm.jsx:
JavaScript

4. Welcome Email on User Registration

Create components/RegistrationForm.jsx:
JavaScript

5. Password Reset Flow

Create components/PasswordResetRequest.jsx:
JavaScript

6. Using Context for Email Service

Create context/EmailContext.jsx:
JavaScript
Use in your app:
JavaScript
If you must use SendPost SDK directly in React (not recommended), create services/sendpostClient.js:
JavaScript
Never expose your API key in client-side code! This example is for demonstration only. Always use a backend API endpoint in production.

8. Environment Variables

Create .env file:

9. Error Handling Best Practices

Create utils/emailErrorHandler.js:
JavaScript
Use in your hook:
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:

React Documentation

Learn more about React framework

SendPost JavaScript SDK

View the official SDK package on npm

Personalization Guide

Learn how to personalize emails with Handlebars templates