Real SMTP via sidecar
Mailgrid's /smtp/send endpoint is HTTP-based. For clients that need TCP SMTP (ports 25/587/465), run a tiny sidecar.
Why a sidecar?
Cloudflare Workers can't listen on raw TCP. That's a platform constraint, not a Mailgrid choice. The workaround is a small SMTP server (running anywhere — Fly, Render, EC2, VPS, Docker on your laptop) that accepts SMTP and forwards each message to Mailgrid's HTTP relay endpoint.
Quickest path: smtp2http
smtp2http is a single Go binary that does exactly this.
smtp2http \ --listen :25 \ --url https://api.mailgrid.space/smtp/send \ --header "Authorization: Bearer mb_live_..."
Point your application's SMTP host config at smtp.yourdomain.com with no auth (or basic auth if you front it with nginx). The sidecar handles SMTP protocol; Mailgrid handles delivery.
Alternatives
- Postfix + a small
transport_mapsrule that pipes tocurl. - Haraka — Node-based SMTP server with HTTP-relay plugin.
- Maddy — modern SMTP, easy config.
Authentication on the sidecar
Best practice: enable SMTP AUTH (basic auth) and inject the Mailgrid bearer token only after auth succeeds. This prevents random internet senders from relaying through your sidecar.
Why doesn't Mailgrid offer SMTP directly?
Three reasons:
- Edge constraint: Workers don't expose TCP listeners.
- Reliability: a sidecar can buffer + retry while Mailgrid is briefly unreachable.
- Cost: TCP infrastructure for SMTP isn't free at scale; HTTP relay leverages Cloudflare's free edge.
For most users, the right answer is "don't use SMTP" — call /api/emails directly. SMTP exists for legacy software you can't change.