Skip to main content
New to the Lettr Python SDK? Start with the Python Quickstart to learn the basics, then return here for Flask-specific integration patterns.
Send transactional emails from your Flask applications using the official Lettr Python SDK. Flask’s flexible architecture makes it easy to integrate Lettr for user notifications, password resets, order confirmations, and other transactional emails.

Prerequisites

Before you begin, make sure you have:

API Key

Create an API key in the Lettr dashboard

Verified Domain

Add and verify your sending domain
You’ll also need:
  • Python 3.8 or later installed
  • Flask web framework
  • A verified sending domain in your Lettr dashboard

Quick Setup

Get started in three quick steps: install dependencies, configure Flask, and send.
1

Install dependencies

This installs the Lettr SDK, Flask web framework, and python-dotenv for environment variable management.
2

Configure environment

Create a .env file in your project root:
Add .env to your .gitignore to prevent committing your API key to version control.
3

Create Flask application

Run with python app.py or flask run.
The sender domain must be verified in your Lettr dashboard before you can send emails. Sending from an unverified domain returns a validation error.

Flask Application Structure

For production applications, organize your code with a proper structure:

Configuration

Create a config.py file for application configuration:

Email Service

Create an email service in services/email.py:

Application Factory

Create an application factory in app.py:

Routes

Create authentication routes in routes/auth.py:

Advanced Features

Using Templates

Send emails using Lettr-managed templates:
See the Python Quickstart for more details on templates, attachments, and other SDK features.

Background Task Queue with Celery

For production applications, send emails asynchronously using Celery:
Create tasks.py:
Use in routes:

Error Handling

Implement error handling in your routes:
See Error Handling in the Python Quickstart for comprehensive error handling patterns.

Testing

Create unit tests for your email service using Flask’s test client:

Best Practices

Use Flask Configuration

Store email settings in Flask configuration:

Logging

Use Flask’s built-in logger:

Rate Limiting

Use Flask-Limiter to prevent abuse:

What’s Next

Python SDK

Complete Python SDK documentation

FastAPI Integration

Use Lettr with FastAPI

API Reference

Complete API documentation

Templates

Use Lettr-managed templates