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

pip

2. Environment Setup

Create a .env file:

3. Basic FastAPI App Setup

Create main.py:
Python

4. Create Email Service

Create services/email_service.py:
Python

5. Create Pydantic Models

Create models/email.py:
Python

6. Send Your First Email

Basic Endpoint

Python

7. Common Use Cases

Welcome Email Endpoint

Python

Password Reset Email

Python

8. Using Dependency Injection

Create dependencies.py:
Python
Use in endpoints:
Python

9. Background Tasks

Use FastAPI’s BackgroundTasks for async email sending:
Python

10. Error Handling

Create exceptions.py:
Python
Use in endpoints:
Python

11. Running the Application

Shell
The API will be available at http://localhost:8000 API documentation (Swagger UI) will be available at http://localhost:8000/docs
Make sure your sender email domain is verified in your SendPost account before sending emails.

12. Next Steps

Explore more examples and use cases:

FastAPI Documentation

Learn more about FastAPI framework

SendPost Python SDK

View the official SDK package on PyPI

Quickstart Example

View a complete working example on GitHub