Send Email from Fly.io Apps with Reloop
Pranav Patel
Co-founder·9 min read
On this page

How to send transactional email from apps on Fly.io: why direct SMTP from Fly machines lands in spam, setting RELOOP_API_KEY with fly secrets, the HTTP API and SMTP relay, background workers, and where to self-host Reloop instead.
Run your app on Fly.io, and send its email through Reloop. Fly is a great place for web apps and workers, but it's a poor place to run a mail server: you can't set reverse DNS (PTR) on Fly IPs, and most large mailbox providers penalize or reject mail from IPs without it. So set RELOOP_API_KEY with fly secrets, send over HTTPS or Reloop's SMTP relay, and let Reloop handle delivery. If you want to self-host Reloop itself, put it on a VPS next to your Fly apps.
This guide covers why, how to wire it up in a few minutes, and how to keep email off your request path with a Fly worker process.
Why not send directly from a Fly machine?
It's tempting to run Postfix, or point Nodemailer straight at recipients' MX servers. Here's what Fly's own staff say about that on the Fly community forum:
- There's no per-account block on outbound port 25.
- But direct-to-MX delivery needs reverse DNS on the sending IP, and Fly doesn't offer customer-configurable PTR records.
- A dedicated egress IP (
fly ips allocate-egress) gives you a stable address, but still no PTR, which "most large receivers will penalize or outright reject." - Their recommendation: relay outbound mail through a transactional email service.
Shared egress IPs make it worse. Anyone else's bad mail from the same IP range affects you, and users regularly report connections to Gmail and other providers timing out or being dropped.
What you need
- An app running on Fly.io (
fly launchin any project). - A Reloop API key from the dashboard. Keys start with
rl_. - A verified sending domain in Reloop. See connect a domain. DNS for your domain lives wherever it does today; it doesn't need to move to Fly.
1. Store the API key as a Fly secret
fly secrets set RELOOP_API_KEY=rl_your_api_key_hereFly encrypts the value and injects it as an environment variable into every machine in the app. Setting a secret triggers a rolling restart, so the new value is live as soon as the command finishes.
Never put the key in fly.toml under [env]. That section is plain text, committed to your repo.
2. Send over HTTPS (recommended)
The HTTP API is the simplest and most reliable option from a container: one HTTPS request on port 443, a JSON response with the email ID, and structured errors.
Node.js
npm install reloop-email1import { Reloop } from "reloop-email";2
3export const reloop = new Reloop({ apiKey: process.env.RELOOP_API_KEY! });1// anywhere on the server2import { reloop } from "./lib/reloop";3
4const { response, emailError } = await reloop.mail.send({5 from: "Acme <hello@mail.acme.com>",6 to: "user@example.com",7 subject: "Your login link",8 html: '<p><a href="https://app.acme.com/login?token=…">Sign in</a></p>',9 text: "Sign in: https://app.acme.com/login?token=…",10 tags: [{ name: "type", value: "magic-link" }],11});12
13if (emailError) {14 console.error(emailError.status, emailError.message);15}The SDK returns { response, emailError } instead of throwing, so a failed send never crashes a request handler. More patterns are in the Node.js email guide.
Any language
It's one POST, so it works from Elixir, Go, Python, Rails or anything else you deploy on Fly:
1curl -X POST https://reloop.sh/api/mail/v1/send \2 -H "x-api-key: $RELOOP_API_KEY" \3 -H "Content-Type: application/json" \4 -d '{5 "from": "Acme <hello@mail.acme.com>",6 "to": "user@example.com",7 "subject": "Hello from Fly.io",8 "text": "Sent from a Fly machine through Reloop."9 }'There are official SDKs for Python, Go, Ruby, PHP, Rust, Elixir and Java as well.
3. Or use the SMTP relay
If your framework already sends through SMTP (Rails Action Mailer, Phoenix Swoosh, Django, Laravel), you don't need to change any code. Just change the settings:
smtp.reloop.sh587 (STARTTLS)Store them as secrets too:
fly secrets set SMTP_HOST=smtp.reloop.sh SMTP_PORT=587 \ SMTP_USERNAME=rl_your_api_key_here SMTP_PASSWORD=rl_your_api_key_hereFor example, in Rails:
1config.action_mailer.delivery_method = :smtp2config.action_mailer.smtp_settings = {3 address: ENV.fetch("SMTP_HOST"),4 port: ENV.fetch("SMTP_PORT").to_i,5 user_name: ENV.fetch("SMTP_USERNAME"),6 password: ENV.fetch("SMTP_PASSWORD"),7 authentication: :plain,8 enable_starttls_auto: true,9}You're connecting to a relay on 587 with authentication, not delivering to recipients' MX on port 25, so the PTR problem above doesn't apply. Examples for other languages are in the SMTP docs.
4. Keep email off the request path with a worker process
Fly apps can run several process groups from one image. Use one for your web server and one for background jobs, and send email from the worker. A slow send never slows a page, and failed sends can be retried.
1app = "acme"2
3[processes]4 web = "node dist/server.js"5 worker = "node dist/worker.js"6
7[http_service]8 internal_port = 30009 processes = ["web"]1// src/worker.ts (sketch using any queue you already run, e.g. BullMQ on Redis)2import { Worker } from "bullmq";3import { reloop } from "./lib/reloop";4
5new Worker(6 "emails",7 async (job) => {8 const { emailError } = await reloop.mail.send(job.data);9 if (emailError && (emailError.status >= 500 || emailError.status === 429)) {10 throw emailError; // let the queue retry11 }12 },13 { connection: { url: process.env.REDIS_URL! } },14);Then scale each group on its own:
fly scale count web=2 worker=1If you can't use a queue but want retries to be safe, call the HTTP API with an Idempotency-Key header. Reloop replays the original response for 24 hours instead of sending twice.
5. Receiving email
Fly apps can't receive mail on port 25 for the same reasons they can't send it well. Use Reloop's inbound instead:
- Turn on receiving for your domain in Reloop and add the MX record it shows.
- Create a webhook for the
email.receivedevent pointing at your Fly app, for examplehttps://acme.fly.dev/webhooks/reloop. - Verify the
Reloop-Signatureheader on each request. See verifying webhooks.
Your Fly app gets a signed JSON event with the sender, subject, thread ID and more. The full message, including attachments, is available through the inbox API.
Should I self-host Reloop on Fly.io?
We don't recommend it, and we don't ship a Fly configuration for it. Reloop's MTA needs to deliver directly to recipients on port 25 and receive on port 25, which runs straight into the PTR limitation. The stack is also a multi-service Docker Compose deployment (around 20 containers and about 22 GB of images), which doesn't map neatly onto Fly Machines.
If you want to run Reloop yourself, use a VPS from a provider that lets you set reverse DNS and open port 25:
Your apps can stay on Fly and point at your instance by setting the SDK's baseUrl, or SMTP_HOST, to your Reloop server.
Checklist
-
RELOOP_API_KEYset withfly secrets set, not infly.toml - Sending domain verified in Reloop (SPF, DKIM, DMARC)
- App sends through the HTTP API or
smtp.reloop.sh:587, never direct-to-MX - User-facing sends happen in a worker process or queue
- Inbound handled by Reloop with a signed
email.receivedwebhook
FAQ
Fly staff say there's no per-account block on outbound port 25. The problem is deliverability: Fly IPs have no customer-configurable reverse DNS, so large mailbox providers penalize or reject direct mail from them.
Yes. That's an authenticated connection to a relay, not direct delivery. If a network ever blocks SMTP ports, the HTTP API on 443 always works.
Wherever your users are. Sending is a single HTTPS request, so region has little effect on email; Reloop queues and delivers it from there.
Yes. Reloop's free tier includes 6,000 emails a month with up to 200 a day, which is plenty for staging apps on Fly.
Ship your first email with Reloop
in minutes.
Open-source, deliverability-focused, and yours to self-host or run on Reloop Cloud. No lock-in, no rewrite later.


