Lightweight FastAPI SMTP proxy with HTTP API, TLS/SSL, and attachments.
156
A lightweight FastAPI service that lets you send emails over a simple HTTP/JSON API instead of talking to SMTP directly. You send it your SMTP server details and the email content in one request, and it relays the message for you.
It's built for situations where you want another app, script, or platform (that only speaks HTTP) to send email without embedding SMTP credentials or an SMTP client library inside it.
POST request to /send (synchronous) or /send_async (queued in the background).smtp_config - host, port, username, password, TLS/SSL flags, timeoutsender - the from-address used for the emailmessages - a list of one or more emails to send (to/cc/bcc, subject, text/HTML body, headers, attachments)Authorization header, connects to your SMTP server, builds the email (including attachments), and sends it.Every request must include:
Authorization: Bearer your-api-key
The token type must match the ALLOWED_TOKEN environment variable, and the key must be listed in ALLOWED_API_KEYS.
| Method | Path | Behavior |
|---|---|---|
| POST | /send | Sends all messages, then responds with results |
| POST | /send_async | Queues sending in the background, responds immediately |
{
"smtp_config": {
"host": "smtp.example.com",
"port": 587,
"username": "[email protected]",
"password": "your-password",
"sender": { "email": "[email protected]", "name": "Example Sender" },
"use_tls": true,
"use_ssl": false,
"timeout": 10
},
"sender": { "email": "[email protected]", "name": "Example Sender" },
"messages": [
{
"to": [{ "email": "[email protected]", "name": "Recipient" }],
"subject": "Test message",
"text_body": "Hello from the SMTP proxy",
"html_body": "<p>Hello from the SMTP proxy</p>"
}
]
}
/send:
{ "message": "1 email's sent successfully, 0 failed.", "status": "success", "sent": 1 }
/send_async:
{ "message": "Email sending initiated in the background.", "status": "initiated", "queued": 1 }
docker run -d \
--name http-smtp-proxy \
--restart unless-stopped \
-p 8000:8000 \
-e ALLOWED_API_KEYS=mykey1,mykey2 \
-e ALLOWED_TOKEN=Bearer \
-e DEBUG=false \
krsahil8825/http-smtp-proxy:latest
The API will be available at http://localhost:8000.
docker run -d \
--name http-smtp-proxy \
--restart unless-stopped \
-p 8000:8000 \
--env-file .env \
krsahil8825/http-smtp-proxy:latest
version: "3.9"
services:
http-smtp-proxy:
image: krsahil8825/http-smtp-proxy:latest
container_name: http-smtp-proxy
restart: unless-stopped
ports:
- "8000:8000"
environment:
- ALLOWED_API_KEYS=mykey1,mykey2
- ALLOWED_TOKEN=Bearer
- DEBUG=false
docker compose up -d
| Variable | Required | Description |
|---|---|---|
ALLOWED_API_KEYS | Yes | Comma-separated list of accepted API keys (e.g. key1,key2,key3) |
ALLOWED_TOKEN | Yes | Token prefix expected in the Authorization header (e.g. Bearer) |
DEBUG | No | Set to true to enable /docs, /redoc, and /openapi.json. Default false |
Keep
DEBUG=falsein production - it disables the interactive docs and schema endpoints.
-p 8000:8000.latest - most recent stable buildv1.0.0, 1.0) - pinned releases for reproducible deploymentsAuthorization header format and that the key/token match ALLOWED_API_KEYS / ALLOWED_TOKEN.ALLOWED_API_KEYS or ALLOWED_TOKEN is set.DEBUG=true temporarily to access /docs, but switch it back off before exposing the service publicly.smtp_config, not baked into the image - the container itself only needs an API key for authenticating callers.Content type
Image
Digest
sha256:1afc90fc6…
Size
62.8 MB
Last updated
about 2 months ago
docker pull krsahil8825/http-smtp-proxy