http_email_backend
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:
- the application runs in a restricted network or container that cannot reach an SMTP server directly
- outbound SMTP ports are blocked by your hosting provider or cloud firewall
- you want to centralize email delivery behind a proxy, queue, or gateway service
- you need a single HTTP hop from Django to a service that already knows how to talk to SMTP
Installation
pip install http_email_backend
Django settings
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"
Required settings
| 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.
Optional settings
| 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 |
SMTP-style settings
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_CERTFILE
EMAIL_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.
How it works
When Django sends an email, this backend:
- Collects the message(s) — recipients, subject, plain-text/HTML body, headers, and attachments.
- Skips any message with no recipients.
- Builds a JSON payload containing the SMTP-style config and the message data.
- Sends the payload with an HTTP
POSTrequest toEMAIL_REQUEST_URL, authenticated withAuthorization: <EMAIL_REQUEST_TOKEN_TYPE> <EMAIL_REQUEST_API_KEY>. - Returns the number of messages sent on success, or
0if 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.
Usage
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"],
)
Notes
- This package is only the Django-side backend. You still need a separate HTTP proxy service that receives the request and performs the actual delivery.
- It does not send mail over SMTP directly — SMTP settings are only forwarded to the proxy for it to use.
- Best suited for deployments where direct SMTP access from the app server is not possible or not desired.
HTTP proxy service Setup
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file http_email_backend-1.0.2.tar.gz.
File metadata
- Download URL: http_email_backend-1.0.2.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0059189e581c3308bf21c3308284289284839c62bb55e0dde3b9cd90ce5a7ae
|
|
| MD5 |
99bcdc909c177472daf82b86202a22fa
|
|
| BLAKE2b-256 |
82465c67af9f3acfd22569b5e57959064213718df2f9276b720dcd8cdb66669f
|
File details
Details for the file http_email_backend-1.0.2-py3-none-any.whl.
File metadata
- Download URL: http_email_backend-1.0.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7671f304c298bd025dce928a4db82ba6e42e7d49399d7ad9dc65d40b29f77fc
|
|
| MD5 |
c779c1401a3213be67431d0768dd0121
|
|
| BLAKE2b-256 |
e4b2ed4d44f88e7e3c75c9f007dd0e45d5420fb7fded09d33d9b8606a659fafb
|