Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Python + Resend Examples

Comprehensive examples for sending emails with Resend using Python.

Prerequisites

  • Python 3.9+
  • pip
  • A Resend account

Installation

# 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 .env

Examples

Basic Email Sending

python examples/basic_send.py

Batch Sending

python examples/batch_send.py

With Attachments

python examples/with_attachments.py

With CID (Inline) Attachments

python examples/with_cid_attachments.py

Scheduled Sending

python examples/scheduled_send.py

Using Templates

python examples/with_template.py

Prevent Gmail Threading

python examples/prevent_threading.py

Audiences & Contacts

python examples/audiences.py

Domain Management

python examples/domains.py

Inbound Email

python examples/inbound.py

Double Opt-In

# Subscribe (creates contact + sends confirmation)
python examples/double_optin_subscribe.py onboarding@resend.dev "John Doe"

# Webhook handler - see flask_app.py for web endpoint

Flask Application

python 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!"}'

FastAPI Application

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!"}'

Django Application

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!"}'

Quick Usage

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']}")

Project Structure

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

Resources

Contributing

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.

License

MIT