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
Release files for http_email_backend 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| http_email_backend-1.0.2.tar.gz | 10.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| http_email_backend-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / http_email_backend-1.0.2.tar.gz
| Download URL | http_email_backend-1.0.2.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f0059189e581c3308bf21c3308284289284839c62bb55e0dde3b9cd90ce5a7ae
|
|
BLAKE2b-256 checksum How to use checksums |
82465c67af9f3acfd22569b5e57959064213718df2f9276b720dcd8cdb66669f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / http_email_backend-1.0.2-py3-none-any.whl
| Download URL | http_email_backend-1.0.2-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7671f304c298bd025dce928a4db82ba6e42e7d49399d7ad9dc65d40b29f77fc
|
|
BLAKE2b-256 checksum How to use checksums |
e4b2ed4d44f88e7e3c75c9f007dd0e45d5420fb7fded09d33d9b8606a659fafb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|