Framework Integration
Django Transactional Email API & SMTP Backend
Send password resets, user activation tokens, and transactional notifications from your Django app with sub-millisecond dispatch and parcel-style receipts.
Native Django Compatibility
SendPorter integrates directly with Django’s built-in django.core.mail subsystem. You can use standard Django email methods without installing heavy third-party packages, or use our official Python SDK for advanced parcel tracking and metadata tags.
Step 1: Django settings.py Configuration
Configure SendPorter as your SMTP backend in your Django project settings. Store your credentials in environment variables to maintain security:
# settings.py
import os
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendporter.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_TIMEOUT = 10 # Seconds
EMAIL_HOST_USER = os.getenv('SENDPORTER_API_KEY') # sp_live_...
EMAIL_HOST_PASSWORD = os.getenv('SENDPORTER_SECRET_KEY') # sp_sec_...
DEFAULT_FROM_EMAIL = 'Security Team <notifications@yourdomain.com>'
SERVER_EMAIL = 'ops@yourdomain.com'Step 2: Sending HTML & Text Emails in Views
Use Django's EmailMultiAlternatives to send both a rich HTML message and a plain text fallback for maximum inbox compatibility:
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
def send_verification_email(user, token):
subject = "Verify your account"
text_content = f"Hi {user.username}, please verify your email using this token: {token}"
html_content = render_to_string("emails/verify.html", {
"user": user,
"token": token,
"verify_url": f"https://yourdomain.com/verify?token={token}"
})
msg = EmailMultiAlternatives(
subject=subject,
body=text_content,
from_email="noreply@yourdomain.com",
to=[user.email]
)
msg.attach_alternative(html_content, "text/html")
# Custom SendPorter headers for parcel classification
msg.extra_headers = {
"X-SendPorter-Tag": "user-verification",
"X-SendPorter-Metadata-User-ID": str(user.id)
}
msg.send(fail_silently=False)Step 3: Background Worker Sending with Celery
In high-traffic Django applications, sending emails synchronously within the HTTP request cycle can increase response latency. Offload sends to Celery for instant page loads:
# tasks.py
from celery import shared_task
from django.core.mail import send_mail
@shared_task(bind=True, max_retries=3, default_retry_delay=60)
def send_transactional_notification_task(self, user_email, subject, message):
try:
send_mail(
subject=subject,
message=message,
from_email="notifications@yourdomain.com",
recipient_list=[user_email],
fail_silently=False,
)
except Exception as exc:
raise self.retry(exc=exc)Frequently Asked Questions
Do I need to install a custom Django email package?
No. Django's built-in django.core.mail.backends.smtp.EmailBackend connects directly to SendPorter's TLS SMTP relay. If you prefer REST API calls, our official sendporter Python SDK is available on PyPI.
How do I track delivery status for emails sent from Django?
Every message sent through SendPorter generates a parcel receipt. You can configure webhooks in your SendPorter console to receive real-time notifications for delivery, opens, clicks, or bounces at a Django webhook endpoint.
Can I use Django templates with SendPorter?
Yes. You can use standard Django DTL or Jinja2 templates, render them to HTML with render_to_string, and pass the output directly into the email body.
Start sending transactional emails from Django
Get your SendPorter API key in minutes. Free 2,500 emails every month.
Request Access