Self-hosted company email with Mailcow: what it takes and what goes wrong
Self-hosted email with Mailcow: hardware, DNS records, a sending relay, certificates, updates and backups, plus the common mistakes to avoid when running your own mail.

The invoice for mailboxes arrives again. Say you have ten people, plus accounts@ and support@, each billed every month, forever. For many businesses hosted mail is the right answer. For some, running your own is a real option. We run our company mail this way.
Why run your own mail
- Cost at scale. Per-seat pricing punishes shared and role addresses. Hosted mail typically costs ₹125 to ₹700 per user per month, so ten people plus a couple of role addresses is roughly ₹18,000 to ₹1,00,000 a year, every year. On your own server, a new mailbox or alias costs nothing.
- Ownership. Your mail sits on your disks, under your backup policy, and no provider can lock an account or change terms under you.
When not to
Skip it if you have a handful of people and no server, or if nobody on the team is comfortable with Linux, Docker and DNS. You become the provider, and when mail stops, nobody else is looking at it. And if a missed message for an hour would cost you real money, pay someone with a support desk.
What you need
Mailcow packages everything a mail server needs into one Docker Compose project: Postfix for sending and receiving, Dovecot for mailboxes, Rspamd for spam, SOGo for webmail and calendars, and a web admin panel. It is free and open source.
- A server. A small N100 or N150 class mini PC with 16 GB of RAM is enough for a small company, roughly ₹15,000 to ₹25,000 new or ₹10,000 to ₹20,000 used (approximate). Ours runs mail alongside everything else. Mailcow's documentation asks for about 6 GB of RAM plus swap as a minimum, and recommends more for a team. ClamAV, the virus scanner, is the biggest user; set
SKIP_CLAMD=yinmailcow.confif memory is tight. We did. - An SSD or NVMe drive for mailboxes and the database, which make lots of small writes.
- A separate backup disk, roughly ₹4,000 to ₹8,000 (approximate). Not a folder on the same drive.
- A UPS, roughly ₹3,000 to ₹8,000 (approximate). Power loss mid-write is how databases get corrupted.
- A domain you control the DNS for, and an account with a sending relay. Many relays have a free tier for low volumes.

How to set it up
1. Install Mailcow
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
./generate_config.sh
docker compose pull
docker compose up -d
Before the last line, check two settings in mailcow.conf. MAILCOW_HOSTNAME is the name other servers will see, such as mail.example.com. TZ is the timezone, and it must be right before anyone logs in. SOGo copies server defaults into each user's profile on first login, so a later change never reaches existing users. Fixing it afterwards means editing saved preferences in the database.
The first pull downloads several gigabytes, so expect a wait on a home line. When it works, https://your-mail-hostname shows the Mailcow login; sign in with the documented default admin account (admin / moohoo), change that password first, then under Mail Setup add your domain and its mailboxes.
2. Publish the DNS records
Getting other servers to trust you happens in DNS. A sanitised set for example.com:
mail.example.com. A <your-public-ip>
example.com. MX 10 mail.example.com.
example.com. TXT "v=spf1 mx include:<relay-spf-domain> ~all"
dkim._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=<public-key-from-mailcow>"
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"
autodiscover.example.com. CNAME mail.example.com.
autoconfig.example.com. CNAME mail.example.com.
MX says which server receives your mail. SPF lists who may send as you; follow your relay's instructions here. DKIM signs outgoing mail. Mailcow generates a 2048-bit key for you (choose 2048 when adding the domain); paste the public part into DNS. It is long, and some DNS panels want it split into two quoted strings. DMARC tells receivers what to do when checks fail; start at p=none, read the reports for a few weeks, then move to p=quarantine once only your server and your relay appear in them. Go to p=reject only when you are sure nothing else sends as your domain (web forms, invoicing tools, a printer). Autodiscover lets phones and Outlook set themselves up.
When it works, Mailcow's DNS check page for the domain shows every record in green.

3. Send through a relay
Most office and home broadband is a poor place to send mail from. Outbound port 25 is often blocked, the address ranges look residential, and you usually cannot set reverse DNS (PTR). Even a perfect server lands in spam.
So hand outgoing mail to a relay on port 587. Your server still receives, stores, filters and signs everything; you only rent the last step. We use Mailtrap. In Mailcow, set it per domain:
- Configuration, Routing, Sender-dependent transports: add the relay host and its credentials.
- Mail Setup, Domains: edit the domain and pick that transport.
When it works, a test message to a Gmail address arrives in the inbox, and "Show original" says SPF, DKIM and DMARC pass. If the relay adds click tracking, Mailcow's own DKIM may show "neutral". That is fine if the relay's DKIM, aligned with your domain, passes.

4. Receive directly
Some providers that block outbound port 25 still leave inbound open. Check yours. Open port 25 on your router and firewall, then connect from outside with an online port checker. When it works, you see your server's greeting, something like 220 mail.example.com.
If your server goes down, senders queue and retry for days. A static IP saves you from waiting on DNS after an address change. On a dynamic IP, run a dynamic DNS client (many routers have one, or a small container) that updates the mail host's A record, and set that record's TTL to 300 seconds. When the address changes, inbound mail is delayed a few minutes rather than lost, because sending servers retry.
5. Put a reverse proxy in front, if you need one
If Mailcow is alone on the server, it handles its own Let's Encrypt certificates. Ours is not. Caddy owns ports 80 and 443 for every site on the machine, so it must pass Mailcow's names through:
mail.example.com, autodiscover.example.com, autoconfig.example.com {
reverse_proxy https://nginx-mailcow:443 {
transport http {
tls_insecure_skip_verify
}
header_up Host {host}
}
}
In mailcow.conf set HTTP_PORT=8080, HTTP_BIND=127.0.0.1, HTTPS_PORT=8443, HTTPS_BIND=127.0.0.1 (Mailcow's documented reverse-proxy values), then docker compose up -d. Caddy's certificate only covers the web panel; IMAP and SMTP use the one acme-mailcow fetches, so pass /.well-known/acme-challenge/ for the mail hostname through to Mailcow's HTTP port. Any other port change goes in docker-compose.override.yml, never the main compose file, which the update script replaces. When adding a name, restart Caddy fully (a reload does not always pick up an edited, bind-mounted Caddyfile), wait for its certificate, then restart acme-mailcow.
When it works, webmail loads over HTTPS and a mail client connects to IMAP without a certificate warning.
6. Move existing mail in
Years of old mail moves well with imapsync, which Mailcow has built in as "Sync jobs" on each mailbox. Fill in the old provider's IMAP host, port 993, SSL, the old username and password, leave "delete from source" unticked and set a 20 to 30 minute interval. Success is a last-run time in the job's status column and a folder tree and message count in webmail that match the old account. A sensible weekend plan:
- Create every mailbox and alias in Mailcow first.
- A day ahead, set the TTL on the MX record and the mail host's A record to 300 seconds. Most DNS hosts default to 3600 or 86400, and caches keep the old value until it expires, which is why it is the day before, not the hour before.
- Run a first sync while the old provider is still live. This moves the bulk.
- Switch the MX record to your server.
- Sync again to catch anything that arrived at the old provider during the switch.
When it works, a test from an outside address lands in the new mailbox.
What goes wrong
Certificates silently missing a name. A common cause is a leftover wildcard AAAA record pointing at an old temporary IPv6 address. Mailcow's certificate script sees it, cannot match it, and drops the name, with only a quiet log line as a clue. Fix: delete the wildcard and apex AAAA records, then restart unbound-mailcow and acme-mailcow. If you publish IPv6, use a stable address, never a privacy one.
All outbound mail using one relay account. An old relay setup in data/conf/postfix/extra.cf can override Mailcow's per-domain lookup, so every domain on the box uses the first relay account and the relay rejects the rest. The mail log says nothing. Check with docker compose exec postfix-mailcow postconf -h smtp_sasl_password_maps; it should show proxy:mysql:, not hash:. Keep relay settings in the admin panel.
Breakage after automatic updates. Mailcow's containers are released together. The symptom is one container restarting in a loop in docker compose ps while the rest look healthy, and webmail or delivery stops. Exclude them from Watchtower or any auto-updater and use ./update.sh on a day you are around. If the host has an IPv6 default route, it may also restart Docker, and every container with it.
No way back. Run helper-scripts/backup_and_restore.sh backup all nightly to the separate disk, and before every update. Test a restore once: run helper-scripts/backup_and_restore.sh restore on a spare machine or VM, log in to its webmail and check that a known mailbox, its folders and its last week of mail are there. Repeat after any big update. A backup you have never restored is a hope.
Cost and time
Hardware is a one-off of roughly ₹20,000 to ₹40,000 bought new, or ₹17,000 to ₹35,000 with a used mini PC (approximate), and much less if a server already exists. Monthly: electricity for a 6 W mini PC is about ₹50 to ₹100, plus domain renewal. A relay's free tier usually covers a very small team; check its monthly message cap against your real volume and budget a few hundred rupees a month above it. At this scale that is a fraction of one hosted mailbox. The install takes an afternoon; DNS, relay and testing take a day or two; migration a weekend. After that, budget an hour or so a month for updates and reading DMARC reports.
Worth it?
With a few people and no server, probably not. With a server already running, many mailboxes or a firm wish to own your data, it is very achievable. Most of the work is DNS, a relay and a few habits.
TDH Systems sets up and looks after business email, file servers and internal tools. See what we build.


