Deploy MailFlow
Unified webmail for all your IMAP accounts in one inbox
Just deployed
Just deployed
postgres
Just deployed
/var/lib/postgresql
Deploy and Host self hosted MailFlow (Other) on Railway
This template deploys MailFlow, a self-hosted unified webmail client, as independent community packaging of maathimself/mailflow v4.5.1 (AGPL-3.0). It is not affiliated with or endorsed by MailFlow.
About Hosting MailFlow open-source software on Railway (self hosted MailFlow template)
MailFlow is a self-hosted unified webmail, so your mail and app state stay under your control. Mail stays on the IMAP and SMTP servers you connect.
Railway handles the plumbing: the services share a private network, the frontend terminates HTTPS at the edge, and the Postgres volume is attached at /var/lib/postgresql.
Why Deploy MailFlow, the self-hosted unified webmail on Railway
Running MailFlow on Railway gives you one inbox for all your IMAP accounts while app state stays in a Postgres service you control.
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying MailFlow on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Railway vs Other Hosting Providers and VPS for MailFlow self hosting
Running MailFlow means keeping three services online: the web app, the backend, and Postgres.
| Provider | What You Get with Railway | What You Get with the Other Provider |
|---|---|---|
| DigitalOcean | Three services from one template, with generated secrets, a Postgres volume and private networking. | A droplet you manage, including the OS, Docker, firewall, TLS and backups. |
| AWS | The frontend, backend and Postgres wired together on first deploy. | Many compute and database options, with more work to connect them. |
| Hetzner | Managed container deployment with restarts, health checks and a stable public domain. | Low-cost servers where you install and maintain the stack yourself. |
Choose Railway for a quick start, or a VPS for direct control of the machine.
Common Use Cases for hosted MailFlow
- Personal inbox across providers: Connect a Gmail account, an Outlook account, a Fastmail account and any other IMAP account, then read them all in one unified inbox sorted by date.
- Shared rules and filters: Set up inbox rules that move, archive, star or mark mail as read based on sender, subject, recipient or headers, so routine mail is handled before you open it.
- Searching across every account: Run full-text search over all connected accounts at once, which helps when a receipt or thread lives in a different mailbox than you expect.
- Contacts and autocomplete: Keep one contact list that learns from the mail you send, so suggestions stay useful across every account you manage.
- Keeping mail on your existing servers: Your messages stay on the mail providers you already use, while MailFlow's own state such as accounts, sessions and settings lives in the bundled Postgres service on Railway.
Dependencies for MailFlow Docker hosted on Railway
This template runs three services on Railway: a public frontend, a private backend, and a private Postgres database.
Deployment Dependencies for Managed MailFlow Service
The frontend is public: Caddy serves the web app on port 80 and also answers on 8080 so the Railway health check at / can pass; the public domain targets port 80. The backend is private on port 8080, with a health check at /api/health and no volume. Postgres is private postgres:16-alpine, with a volume at /var/lib/postgresql and restart policy On Failure. The frontend and backend restart policy is Always. Keep one replica of each service.
Implementation Details for MailFlow
The images are ghcr.io/onepush-dev/mailflow-frontend:4.5.1 and ghcr.io/onepush-dev/mailflow-backend:4.5.1, which are the unmodified upstream ghcr.io/maathimself/mailflow-frontend:4.5.1 and mailflow-backend:4.5.1 images with Railway defaults baked in. The frontend sets TLS_MODE=off and BACKEND_PORT=8080, and ships a sites-off.caddy file so Caddy listens on port 80 and port 8080. The backend sets NODE_ENV=production, PORT=8080, TRUST_PROXY_HOPS=2 (Railway edge plus Caddy), DB_PORT=5432, DB_NAME=postgres, DB_USER=postgres, IMAGE_CACHE_DIR=/var/cache/mailflow/images and IMAGE_CACHE_MAX_MB=512. That image cache is not on a volume, so it is lost on redeploy. Migrations run on backend boot. Redis is not included and is not required since 4.4.
How does MailFlow compare against other tools
MailFlow vs a hosted webmail service (Hosted Webmail Alternative)
- Data location: MailFlow runs in your own Railway project, so the app and Postgres database sit in infrastructure you control, while mail stays on your IMAP servers.
- Account mixing: MailFlow merges several IMAP and SMTP accounts into one inbox.
- Where a hosted service wins: a hosted provider handles uptime, spam filtering and updates for you.
MailFlow vs a desktop mail client alone (Desktop Client Alternative)
- Shared inbox: MailFlow gives you one web inbox you can open from any browser.
- Rules and search: MailFlow adds inbox rules, contacts and full-text search across all connected accounts.
- Where a desktop client wins: it keeps working offline, while MailFlow needs its backend and database running.
MailFlow with Docker vs Railway (Railway Hosting Alternative)
- Setup effort: the Railway template creates the frontend, backend and Postgres services with no inputs, while Docker means writing the Compose file yourself.
- Persistence: Postgres has a volume at /var/lib/postgresql, while the frontend and backend have no volume and their image cache is lost on redeploy.
- Where Docker wins: a Docker host gives you direct control over networking and backups. Register the first account right after deploy, since it becomes the admin and registration then closes.
How to use MailFlow on Railway?
- Open the public frontend domain and register the first account immediately. That user becomes the admin, and registration then closes.
- Sign in, then add your IMAP or SMTP accounts under Settings.
- If you add a custom domain, update APP_URL and FRONTEND_URL together so they match.
- Keep ENCRYPTION_KEY and SESSION_SECRET stable. Changing ENCRYPTION_KEY after accounts are added will make stored mail passwords unreadable.
- Keep one replica of each service, since the postgres volume and local state are single-instance.
Health checks used by this template:
frontend: /
backend: /api/health
How to self host MailFlow on other VPS Services (MailFlow self hosting guide)
Clone the Repository
Clone the upstream repository and check out the release tag so you run MailFlow 4.5.1.
git clone https://github.com/maathimself/mailflow.git your-domain-mailflow
cd your-domain-mailflow
git checkout v4.5.1
Install Dependencies
You need a Linux VPS with Docker and Docker Compose installed. Redis is not needed since 4.4, so you only run the frontend, the backend and PostgreSQL.
Configure Environment Variables
Create an environment file with a long random session secret and a 64-character hex encryption key.
SESSION_SECRET=replace-with-a-long-random-string
ENCRYPTION_KEY=replace-with-64-hex-characters
APP_URL=https://your-domain.example
FRONTEND_URL=https://your-domain.example
Start the MailFlow Application
Use the upstream flow: follow the documented Compose or native install, which uses the frontend and backend images plus Postgres. See the upstream repository for the current compose file and details.
Pricing and License of MailFlow (MailFlow pricing)
MailFlow is open-source software released under the AGPL-3.0 licence, so you can self-host it without paying the upstream author for the software itself.
MailFlow hosted vs self hosted comparison (Pricing, features, costs, and more)
This template packages the AGPL-3.0 software.
Monthly cost of self hosting MailFlow on Railway
Railway billing is usage-based. Check your Railway dashboard after a few days of real mail to see what your setup costs.
System Requirements for Hosting MailFlow on a VPS
On a VPS you manage the frontend, backend, and Postgres yourself. Requirements grow with the number of connected accounts and message volume, so measure your own usage.
MailFlow is released under AGPL-3.0. The upstream author also offers a separate commercial licence; this packaging is the self-host images only, and no licence prices are quoted here. Optional extras you can add later on the backend include VAPID keys for web push and OAuth client credentials for Google or Microsoft accounts. None of those are template variables, and they are not required to register the first admin or to add a regular IMAP account. The template asks for no inputs at deploy time: session and encryption secrets and the Postgres password are generated for you.
Frequently Asked Questions (FAQs)
Who is the first admin?
The first account you register after deploy becomes the admin, and registration then closes to invitations only. Register immediately after the frontend is live so that no one else claims the admin role.
What should I back up?
Back up the Postgres volume at /var/lib/postgresql, since that holds your accounts, messages and settings.
Is Redis included?
No, Redis is not included in this template. It is not required since upstream 4.4, so you do not need to add it.
How do I add Gmail or Outlook?
Sign in, then add the IMAP or SMTP account under Settings. You can later add optional OAuth keys for Google and Microsoft accounts if you want that sign-in flow.
Is this affiliated with MailFlow?
No, this is independent community packaging of maathimself/mailflow v4.5.1 and is not affiliated with or endorsed by MailFlow.
Template Content
