Learn how to integrate Django with Resend SMTP.
virtualenv
pip install virtualenv
virtualenv venv source venv/bin/activate
pip install -r requirements.txt
RESEND_API_KEY
export RESEND_API_KEY="re_xxxxxxxxx"
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' RESEND_SMTP_PORT = 587 RESEND_SMTP_USERNAME = 'resend' RESEND_SMTP_HOST = 'smtp.resend.com'
get_connection
EmailMessage
import os from django.conf import settings from django.http import JsonResponse from django.core.mail import EmailMessage, get_connection # Sample Django view def index(request): subject = "Hello from Django SMTP" recipient_list = ["delivered@resend.dev"] from_email = "onboarding@resend.dev" message = "<strong>it works!</strong>" with get_connection( host=settings.RESEND_SMTP_HOST, port=settings.RESEND_SMTP_PORT, username=settings.RESEND_SMTP_USERNAME, password=os.environ["RESEND_API_KEY"], use_tls=True, ) as connection: r = EmailMessage( subject=subject, body=message, to=recipient_list, from_email=from_email, connection=connection).send() return JsonResponse({"status": "ok"})
Was this page helpful?