Skip to main content

SMTP Gateway (smtp-gateway)

Flask API that sends mail through an internal SMTP relay after checking caller IP (CIDR), bearer token, recipient domains, and PII column names in HTML bodies and CSV/HTML attachments. Optional audit to Azure ADLS and notification emails.

Install

Git is not required. See PUBLISHING.md.

From PyPI (after you publish)

pip install "smtp-gateway==1.0.0"

On VM without PyPI (copy wheel)

pip install /path/to/smtp_gateway-1.0.0-py3-none-any.whl

From project folder (no git, no PyPI)

pip install .

Local development

pip install -e .

Required configuration

Copy .env.example to .env on the server and set at least:

Variable Purpose
API_TOKEN Clients send Authorization: Bearer <token>
FROM_EMAIL Gateway sender address
SMTP_SERVER Internal SMTP host
ALLOWED_DOMAINS Comma-separated recipient domains

Startup fails if any required variable is missing.

PII blocklist and caller CIDRs

The package ships example JSON under smtp_gateway/data/:

  • blocklist.json — sample column names
  • allowed_cidrs.json — empty list (blocks all IPs until you configure)

For production, point to your own files (recommended):

export BLOCKLIST_PATH=/etc/smtp-gateway/blocklist.json
export ALLOWED_CIDRS_PATH=/etc/smtp-gateway/allowed_cidrs.json

Format: JSON arrays. Blocklist entries are strings (one column name per entry). CIDRs are strings like "10.0.0.0/24".

Without ALLOWED_CIDRS_PATH, bundled allowed_cidrs.json is used — empty [] means every caller gets 403 Forbidden IP.

Optional

Variable Purpose
SECURITY_ALERT_EMAIL / SECURITY_ALERT_CC Email on blocked requests
AUDIT_NOTIFICATION_EMAIL / AUDIT_NOTIFICATION_CC Audit copy per send/block
ADLS_ACCOUNT_NAME, ADLS_CONTAINER_NAME, MANAGED_IDENTITY_CLIENT_ID ADLS audit (skipped if unset)
GUNICORN_WORKERS, BIND Process count and listen address

Run

Production (HA — use behind a load balancer, 2+ VMs):

set -a && source .env && set +a
smtp-gateway

Equivalent:

gunicorn -w 4 -b 0.0.0.0:5000 'smtp_gateway.app:create_app()'

Local development (Flask dev server):

set -a && source .env && set +a
python -m smtp_gateway

Health check: GET /health → {"status":"healthy"}.

API

POST /send-mail (multipart form):

Field Required Notes
to yes Recipient(s)
subject yes
body yes HTML (table headers scanned for PII)
cc no
file no .csv, .html, .htm only

Headers:

  • Authorization: Bearer <API_TOKEN>
  • Caller IP must match allowed_cidrs.json

Client checklist

  • Call from an allowed CIDR
  • Use allowed recipient domains
  • Avoid blocklisted column names in HTML tables and CSV/HTML attachments

Package layout

src/smtp_gateway/
  app.py              create_app()
  config.py           environment settings
  routes/             /health, /send-mail
  security/           CIDR, domains, auth
  pii/                extract, blocklist, matcher
  audit/              ADLS, email notifications
  data/               bundled example JSON

What you supply vs what is bundled

Bundled in package You supply on the VM
PII matching code Full blocklist.json via BLOCKLIST_PATH
Example blocklist Real allowed_cidrs.json via ALLOWED_CIDRS_PATH
Flask routes, audit code .env secrets and SMTP/ADLS access
smtp-gateway CLI Load balancer, systemd, managed identity + RBAC

Metadata

Release files for smtp-gateway 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smtp-gateway 1.0.1
File Size Uploaded Provenance Actions
smtp_gateway-1.0.1.tar.gz 13.4 kB Without provenance Details for smtp_gateway-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smtp-gateway 1.0.1
File Interpreter ABI Platform Actions
smtp_gateway-1.0.1-py3-none-any.whl Python 3 none any Details for smtp_gateway-1.0.1-py3-none-any.whl

Total release size: 30.1 kB

Release files / smtp_gateway-1.0.1.tar.gz

Download URL smtp_gateway-1.0.1.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
472218db3c220898a6827dc39724f832f0212ad39ec840aa839e8ca4a844f6ec
BLAKE2b-256 checksum
How to use checksums
823da3c3cf8696462c827a459b61a2e4489da56ac607a279069fb35b9b0fabd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / smtp_gateway-1.0.1-py3-none-any.whl

Download URL smtp_gateway-1.0.1-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fdfe0749ef24defe097fb98da723a02bb00c6042c6a15ab47bf65ea83afc43f
BLAKE2b-256 checksum
How to use checksums
c376a37cd0d191dabeb3fb42e9483903653145f05f1f84328d8c2e93868b7823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for smtp-gateway 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page