Comprehensive examples for sending emails with Resend using Python.
- Python 3.9+
- pip
- A Resend account
# Create virtual environment (optional)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy environment variables
cp .env.example .env
# Add your Resend API key to .envpython examples/basic_send.pypython examples/batch_send.pypython examples/with_attachments.pypython examples/with_cid_attachments.pypython examples/scheduled_send.pypython examples/with_template.pypython examples/prevent_threading.pypython examples/audiences.pypython examples/domains.pypython examples/inbound.py# Subscribe (creates contact + sends confirmation)
python examples/double_optin_subscribe.py onboarding@resend.dev "John Doe"
# Webhook handler - see flask_app.py for web endpointpython examples/flask_app.py
# Then in another terminal:
curl -X POST http://localhost:5000/send \
-H "Content-Type: application/json" \
-d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Flask!"}'python examples/fastapi_app.py
# Then in another terminal:
curl -X POST http://localhost:8000/send \
-H "Content-Type: application/json" \
-d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from FastAPI!"}'cd django_app
pip install django
python manage.py runserver 8001
# Then in another terminal:
curl -X POST http://localhost:8001/send \
-H "Content-Type: application/json" \
-d '{"to": "delivered@resend.dev", "subject": "Hello", "message": "Hi from Django!"}'import resend
resend.api_key = "re_xxxxxxxxx"
result = resend.Emails.send({
"from": "Acme <onboarding@resend.dev>",
"to": ["delivered@resend.dev"],
"subject": "Hello",
"html": "<p>Hello World</p>",
})
print(f"Email ID: {result['id']}")python-resend-examples/
├── examples/
│ ├── basic_send.py # Simple email sending
│ ├── batch_send.py # Multiple emails at once
│ ├── with_attachments.py # Emails with files
│ ├── with_cid_attachments.py # Inline images
│ ├── scheduled_send.py # Future delivery
│ ├── with_template.py # Using Resend templates
│ ├── prevent_threading.py # Prevent Gmail threading
│ ├── audiences.py # Manage contacts
│ ├── domains.py # Manage domains
│ ├── inbound.py # Handle inbound emails
│ ├── flask_app.py # Flask web application
│ └── fastapi_app.py # FastAPI web application
├── django_app/ # Django web application
│ ├── manage.py
│ ├── django_project/
│ └── resend_app/
├── requirements.txt
├── .env.example
└── README.md
See something that could be improved? We welcome contributions! Open an issue to report a bug or suggest an improvement, or submit a pull request with your changes.
MIT