Skip to content

resend/resend-django-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resend with Django (using django-anymail)

This example demonstrates how to integrate Resend with Django using django-anymail, which provides a Django email backend for Resend. This approach uses Django's standard email API (send_mail(), EmailMessage, etc.)

Prerequisites

To get the most out of this guide, you'll need to:

Instructions

  1. Create and activate a new virtual env:
virtualenv venv
source venv/bin/activate
  1. Install dependencies (includes django-anymail with Resend support):
pip install -r requirements.txt
  1. Set your RESEND_API_KEY environment variable:
export RESEND_API_KEY="re_123456789"
  1. Navigate to the Django project directory and run the development server:
cd resend_django_example
python manage.py runserver
  1. Test the email endpoints using curl:

    Simple email (default recipient):

    curl -X POST http://127.0.0.1:8000/send/

    Simple email (custom recipient):

    curl -X POST -d "[email protected]" http://127.0.0.1:8000/send/

    Template-based email (default recipient):

    curl -X POST http://127.0.0.1:8000/template_send/

    Template-based email (custom recipient):

    curl -X POST -d "[email protected]" http://127.0.0.1:8000/template_send/

What's Included

This example demonstrates three patterns for sending emails in Django:

1. Simple Email (/send/ route)

Uses Django's send_mail() function - the simplest way to send emails in Django.

2. Template-Based Email (/template_send/ route)

Shows how to use Django templates for email content with:

  • Django's render_to_string() for template rendering
  • EmailMessage class for more control
  • Resend-specific features like tags via esp_extra

3. Email Template (templates/emails/welcome.html)

A reusable HTML email template that demonstrates:

  • Template variables (user_name, user_email, etc.)
  • Professional email styling
  • Django template system integration

Configuration

The django-anymail backend is configured in settings.py:

# Add anymail to INSTALLED_APPS
INSTALLED_APPS = [
    # ...
    'anymail',
]

# Configure Anymail with Resend backend
EMAIL_BACKEND = "anymail.backends.resend.EmailBackend"

ANYMAIL = {
    "RESEND_API_KEY": os.environ.get("RESEND_API_KEY"),
}

DEFAULT_FROM_EMAIL = "[email protected]"

Learn More

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •