http_email_backend is a Django email backend for projects that cannot (or should not) send SMTP traffic directly from the application server.
Instead of opening an SMTP connection itself, it sends a single HTTP POST request to an email proxy service you control. The proxy service is then responsible for relaying the message via SMTP (or any delivery method it implements).
This is useful when:
pip install http_email_backend
Set the backend and its connection settings in settings.py:
EMAIL_BACKEND = "http_email_backend.HttpProxyEmailBackend"
# Forwarded to the proxy as the SMTP config it should use for delivery
EMAIL_HOST = os.getenv("EMAIL_HOST", "localhost")
EMAIL_PORT = int(os.getenv("EMAIL_PORT", "25"))
EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER", "")
EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD", "")
EMAIL_USE_TLS = os.getenv("EMAIL_USE_TLS", "False").lower() == "true"
EMAIL_USE_SSL = os.getenv("EMAIL_USE_SSL", "False").lower() == "true"
EMAIL_TIMEOUT = (
int(os.getenv("EMAIL_TIMEOUT")) if os.getenv("EMAIL_TIMEOUT") else None
)
EMAIL_SSL_KEYFILE = os.getenv("EMAIL_SSL_KEYFILE", None)
EMAIL_SSL_CERTFILE = os.getenv("EMAIL_SSL_CERTFILE", None)
# Proxy-specific settings, required by this backend
EMAIL_REQUEST_URL = os.getenv("EMAIL_REQUEST_URL")
EMAIL_REQUEST_API_KEY = os.getenv("EMAIL_REQUEST_API_KEY")
EMAIL_REQUEST_TOKEN_TYPE = os.getenv("EMAIL_REQUEST_TOKEN_TYPE", "Bearer")
EMAIL_FAIL_SILENTLY = os.getenv("EMAIL_FAIL_SILENTLY", "False").lower() == "true"
| Setting | Description |
|---|---|
EMAIL_REQUEST_URL |
HTTP endpoint that accepts the email payload |
EMAIL_REQUEST_API_KEY |
API key sent in the Authorization header |
The backend raises ImproperlyConfigured on import, and ValueError on instantiation, if either of these is missing.
| Setting | Default | Description |
|---|---|---|
EMAIL_REQUEST_TOKEN_TYPE |
"Bearer" |
Prefix used in the Authorization header, e.g. Bearer <api_key> |
EMAIL_FAIL_SILENTLY |
False |
If True, request failures are swallowed instead of raised |
These are not used to open an SMTP connection locally — they are forwarded to your proxy as part of the JSON payload, so the proxy knows how to deliver the message:
EMAIL_HOSTEMAIL_PORTEMAIL_HOST_USEREMAIL_HOST_PASSWORDEMAIL_USE_TLSEMAIL_USE_SSLEMAIL_TIMEOUTEMAIL_SSL_KEYFILEEMAIL_SSL_CERTFILEEMAIL_USE_TLS and EMAIL_USE_SSL are mutually exclusive; setting both raises a ValueError.
The sender address included in the payload is taken from EMAIL_HOST_USER.
When Django sends an email, this backend:
POST request to EMAIL_REQUEST_URL, authenticated with Authorization: <EMAIL_REQUEST_TOKEN_TYPE> <EMAIL_REQUEST_API_KEY>.0 if there was nothing to send.If the HTML body is present, it is automatically inlined with premailer before being sent, so CSS <style> blocks work reliably in email clients.
If the proxy request fails and EMAIL_FAIL_SILENTLY is False, the backend raises the underlying requests exception. If EMAIL_FAIL_SILENTLY is True, the failure is ignored and 0 messages are reported as sent.
Once configured, use Django’s mail API as usual — no code changes needed:
from django.core.mail import send_mail
send_mail(
subject="Hello",
message="This message is sent through the HTTP proxy backend.",
from_email="webmaster@localhost",
recipient_list=["user@example.com"],
)