Blog

/

Mailgun alternative: a self-hosted replacement on Cloudflare

Mailgun is the developer-oriented transactional email API most teams reach for first — HTTP and SMTP in one product, decent SDKs, route-based inbound. The self-hosted Cloudflare version keeps the API shape and the deliverability discipline, and trades Sinch's pricing curve for Cloudflare's own.

Where Mailgun has been the default

Mailgun's shape is one of the originals: an HTTP API for send that mirrors an SMTP relay for legacy apps, plus a Routes product for inbound that runs regular-expression matching on recipient addresses and forwards to a webhook or stores mail in a mailbox. The SDKs are tight; the documentation is thorough; the operational story is well-understood.

Under Sinch's ownership the pricing has crept up. The 2026 tiers start around $35/month for 50,000 emails on the Foundation plan and climb from there; verification logs and inbound retention are paid add-ons above the plan cap. The per-message overage on the standard tier is around $0.0008, which adds up at scale.

The Cloudflare-native shape

Flowmails is the same shape — HTTP API for send, route tables for inbound — running on a Worker in your Cloudflare account. Outbound uses Email Services for signing and delivery; inbound uses Email Routing to catch the message and the Worker to persist it. Mail data lands in your D1; attachments in your R2. There is no Sinch Postgres in the loop, no shared relay, and no third-party data processor in your privacy notice.

The route-tables model is the closest analog to Mailgun's Routes — both are regular-expression-friendly matchers on the recipient address, with the same "forward, store, or drop" outcomes. The Flowmails version stores the matched route alongside the message row in D1 so you can query "every inbound hit on rule X in the last week" without a separate log API. The detail is in the route tables explainer.

API and SDK translation

The HTTP send endpoint mirrors Mailgun's POST /v3/{domain}/messages: same form-encoded body shape, same attachment model, same recipient-list format. The auth changes from Mailgun's api:key Basic scheme to a per-domain bearer token issued at onboarding. Routes translate one-for-one to the route-tables resource; the webhook delivery shape is identical, including the HMAC-SHA256 signature header.

The Node SDK that ships with @flowmails/sdk follows the same call patterns the official Mailgun SDK uses, so a service that calls mg.messages.send() today can move to flowmails.messages.send() with a one-line import change. The full install shape is on the Cloudflare Workers integration page.

Deliverability, the part that matters

Mailgun's deliverability story is mature: shared IPs with warm-up programs, dedicated IP on the higher tiers, aggressive bounce handling. The Cloudflare-native version inherits Email Services's own outbound infrastructure, which means you share the warm-up posture of the Cloudflare network rather than a Sinch IP pool. Dedicated IPs are a per-zone configuration in Cloudflare, available on the Business and Enterprise plans.

Bounce handling is the Worker's job. Hard bounces (5xx SMTP at the recipient MX) flip a per-recipient suppression flag in D1; soft bounces (4xx with retry semantics) bump a counter and trip the same suppression after three attempts. Spam complaints land via the Feedback Loop headers Cloudflare forwards, and the suppression list is consulted before every send. The same audit log Mailgun exposes on its dashboard is a SQL query against D1.

When the self-hosted version is the right answer

The self-hosted alternative wins when your domain already lives on Cloudflare, when your team is comfortable reading a D1 row directly, and when the operational cost of owning a Worker is smaller than the Sinch bill. The full feature diff is on the Flowmails vs Mailgun matrix; the short version is on the Mailgun alternative page. If neither sounds right and you would rather stay with a hosted provider, the pricing page has the per-tier comparison against Mailgun, Postmark, and SendGrid.

When Mailgun is still the right call

If you need a fully managed SMTP relay that talks to legacy MTAs without an HTTP translation layer, if your inbound retention requirement is >1 year and you don't want to size the D1 / R2 yourself, or if you are on a Sinch master contract that already includes Mailgun, the case for switching is thin. For everyone else in 2026 — especially teams whose Cloudflare bill is already substantial — the self-hosted Mailgun alternative is the better default.

Try the self-hosted Mailgun alternative on Cloudflare.