Skip to main content
Self Hosting Tutorials

Setup Your Own Email Server with Mailcow

Mailcow makes self hosting email server a lot easier. Let me share how I did it in this tutorial.

Abhishek Kumar

Warp Terminal

Email hosting is one of those sneaky expenses that often catches you off guard. You buy a domain, set up a few email addresses, and everything seems fine until the renewal period comes around.

Suddenly, you're faced with exorbitant fees, charged on a per-user basis. This got me thinking, if I host nearly every major service I use, why not host my own email server? 💭

Although, there are mixed opinions on the internet about the whole idea of hosting your own email server. Some people claimed it’s not a great idea, citing complexities and potential issues with email deliverability.

Others, mostly amateurs like myself, had set up their email servers and were happy with the results.

The logical side of me hesitated, but the curious kid inside wanted to try it anyway. After all, isn’t the best way to learn by making mistakes? So, here’s how I self-hosted an email server with Mailcow, with a fair share of trial and error.

Why Mailcow?

During my research, I stumbled upon Mailcow, an open-source project designed to simplify email hosting.

Think of it as a pre-configured email server toolkit, wrapped neatly in Docker containers.

Mailcow combines all the key components - Postfix, Dovecot, SOGo (webmail), and more and provides a clean web interface for managing users, domains, and mailboxes.

  1. Ease of Use: Dockerized setup means less tinkering with dependencies.
  2. Modern Interface: A web dashboard to manage everything (goodbye, terminal-heavy configs).
  3. Community Support: Tons of tutorials, forums, and Reddit discussions to fall back on.

Getting started: What you’ll need

Before we dive in, let’s ensure you’re equipped:

Hardware: You’ll need a server with enough resources for your email needs. For personal use or a small setup, something like 2 vCPUs, 4 GB RAM, and 60 GB storage should be enough.

DigitalOcean – The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size – faster than ever before.

Get started on DigitalOcean with a $100, 60-day credit for new users.

Customer Referral Landing Page - $100
Cut Your Cloud Bills in Half Deploy more with Linux virtual machines, global infrastructure, and simple pricing. No surprise bills, no lock-in, and the

Get started on Linode with a $100, 60-day credit for new users.

A clean Linux installation (e.g., Ubuntu 20.04 or newer). Avoid running other services on the same server.

Static IP Address that isn’t blacklisted. Essential for smooth communication with other mail servers.

Domain Name: You’ll need a domain for your email addresses.

Basic understanding of email protocols like SMTP, IMAP, and POP3.

Familiarity with DNS records (MX, SPF, DKIM, DMARC).

Got all that? Great. Let’s get started!

Setting up the environment

For this guide, I set up a virtual private server (VPS) using Linode with the following specifications 4 GB RAM, 2 vCPUs, 80 GB storage.

choosing a linode plan

For the operating system, I used Ubuntu 22.04 LTS. Once the VPS was ready, I proceeded with the setup steps below.

linode vm setting page

Install docker

We’ve covered the steps to install Docker and Docker Compose multiple times in our previous articles, so I won’t repeat them here.

If you’re new to Docker or need a refresher, you can refer to our guide on how to install Docker on Ubuntu. It’s straightforward and will get you up and running in no time.

Learn Docker: Complete Beginner’s Course
Learn Docker, an important skill to have for any DevOps and modern sysadmin. Learn all the essentials of Docker in this series.

Open necessary ports

Email servers rely on specific ports for communication. Ensure your firewall allows the following:

  • 25 (SMTP)
  • 80 (HTTP)
  • 443 (HTTPS)
  • 587 (SMTP with authentication)
  • 993 (IMAP)

Use this command to verify:

netstat -tulpn | grep -E '25|80|443|587|993'
checking the necessary ports if they are open or not

This ensures smooth communication for sending and receiving emails.

DNS configuration

Proper DNS setup is critical for email functionality. Your domain needs to know where to send email traffic. Here’s a quick guide:

  • A Record: Maps mail.yourdomain.com to your server’s IP address
  • MX Record: Directs incoming emails to mail.yourdomain.com
  • SPF, DKIM, and DMARC: These records authenticate your emails and reduce the chances of them being flagged as spam

If you’re new to DNS, don’t worry, it’s mostly copy-paste.

For managing my DNS records, I’m using Cloudflare, it’s my go-to for all things DNS. Your setup might differ; you could be using your domain registrar’s DNS panel or another provider entirely.

Regardless of the platform, the steps remain similar, so just adapt them to your tool of choice.

A Record

Name: mail

Type: A

Value: Your server’s public IP
adding an A record type to dns setting

CNAME Records

  1. autoconfig
Name: autoconfig

Type: CNAME

Alias: mail.yourdomain.com
adding an CNAME record type with autoconfig to dns setting
  1. autodiscover
Name: autodiscover

Type: CNAME

Alias: mail.yourdomain.com
adding an CNAME record type with autodiscover to dns setting

MX Record

Name: @

Type: MX

Priority: 10

Mail Exchange: mail.yourdomain.com
adding an MX record type to dns setting

SPF Record

Name: @

Type: TXT

Value: v=spf1 ip4:your_server_ip -all
adding an TXT record type for SPF to dns setting

DKIM Record

We will generate a key later during Mailcow setup.

Name: dkim._domainkey

Type: TXT

Value: v=DKIM1;k=rsa;t=s;s=email;p=...

Installing mailcow

Now begins the fun part. First thing first, clone the mailcow repository to your server:

git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
cloning mailcow repo to our server locally

Generate the Configuration

Run this script to create your server’s configuration:

💡
You need to be root for this script to create the necessary config files.
./generate_config.sh

It’ll ask for FQDN i.e. your domain. Use mail.yourdomain.com. This step also sets up SSL certificates using Let’s Encrypt.

running the configuration script to generate the important files to run mailcow

Setting up the containers

With all the groundwork laid, it’s time to bring your email server to life. To get everything running, use the following command:

docker-compose up -d  

Here’s what’s happening, Docker will automatically check for updates to the Mailcow containers (if needed) and then download and launch everything : your mail server, web interface, spam filters, and more, all in one go.

The -d flag stands for "detached," meaning the containers will run in the background, letting you carry on with other tasks while everything boots up.

Depending on your system and internet speed, this step might take a few minutes, so feel free to grab a coffee while your server springs to life.

using docker compose command to start the mailcow containers

Configuring Mailcow

Now that your Mailcow server is up and running, it’s time to configure it to actually handle your emails. First things first, let’s log in to the Mailcow admin interface.

To do that, head over to https://mail.yourdomain.com , you’ll be prompted to log in using the default credentials:

  • Username: admin
  • Password: moohoo
🚧
Keeping the default login is a huge security risk and could leave your server vulnerable to attacks. As soon as you log in, head straight to the settings and set a strong, unique password for your admin account.
mailcow login during initial setup with default credentials

Adding domain

With your admin access secured, let’s add your domain. Head to the Configuration tab at the top of the dashboard under E-Mail.

accessing the configuration page to add domain

Here’s where you’ll add the domain name you’re using for your email (e.g., yourdomain.com).

In simple words, this step is essentially telling Mailcow, “Hey, this is the domain we’ll be using to send and receive emails,” so make sure it’s the right one.

clicking on the add domain button

Once you’ve added it, click the Add Domain and restart SOGo button, and you’re all set for the next step.

once done, press add domain and restart sogo button at the bottom

Generate DKIM Keys

DKIM (DomainKeys Identified Mail) is a way to sign your emails so that receiving servers can verify they’re coming from you and haven’t been tampered with.

It’s an essential part of keeping your emails from ending up in the spam folder.

To generate DKIM keys for your domain, head to Configuration > ARC/DKIM Keys in Mailcow.

This section allows you to create a unique DKIM key for your domain.

generating dkim key from the configuration menu

Once the key is generated, you’ll need to copy it and add it as a TXT record in your domain’s DNS settings (discussed above).

adding dkim key to the cloudflare dns settings

This step may take some time to propagate, but don’t worry once it’s done, your emails will be much more secure.

Create mailboxes

With your domain configured and your DKIM keys set up, you’re ready to start creating mailboxes.

This is where you’ll set up individual email accounts for yourself, your team, or anyone else who needs an email address under your domain.

Go to Mail Setup > Mailboxes in Mailcow’s dashboard. Here, you’ll see an option to Add Mailbox.

creating mailbox

Simply choose a username, assign it to your domain, create a password, and hit Add Mailbox.

setting up a user for mailbox

You can add as many mailboxes as you need, whether it's for yourself or your colleagues.

💡
By default, Mailcow will allocate 10GB of storage to every domain, with each mailbox under that domain getting 3GB of storage. If you need more space or want to adjust the limits for your mailboxes, feel free to modify them in the Mailcow settings to suit your needs.
when ready you can see the mailbox listed with other settings

After you’ve created your mailboxes, you can test them by logging into the webmail interface. Just head over to Apps > Webmail.

accessing webmail from the homepage

and log in using the email account you just created.

sogo webmail login page

Once you’ve done this, your basic Mailcow setup is ready to go! You now have a fully functional mail server running on your domain, capable of sending and receiving emails. But hold on, this is where things get interesting.

webmail inbox

During my testing, I sent two emails: one to my Microsoft Outlook account

email received on outlook web

and another to my domain account hosted on ProtonMail.

email received on protonmail web client

To my dismay, both emails went straight to the Junk/Spam folder!

After a bit of troubleshooting, I realized this was likely because I hadn’t set up a DMARC record yet.

Without DMARC, email providers often flag messages as suspicious, even if the server setup looks otherwise fine.

So while your Mailcow setup might technically be complete at this stage, there’s still important work ahead.

Fine-tuning these configurations and conducting more tests are essential to making your mail server truly robust.

email received in cowmail that is sent from an outlook account
Here I send myself an email from my outlook account and it directly went to my cowmail inbox

Final thoughts

When I first started setting up my email server, I was amazed at how Mailcow made everything feel so accessible.

With its streamlined interface and pre-configured Docker containers, I couldn’t help but wonder, Why don’t more people use this? It seemed like the perfect solution until I dug deeper.

Running Mailcow isn’t just about spinning up some containers. It’s the whole other layer of responsibility that comes with managing your IP.

From ensuring your IP reputation stays clean to avoiding blacklists, to setting up a static IP, it can get overwhelming fast. These aren’t things Mailcow can solve for you, and they’re the very reasons managed services exist.

For most people, clicking “sign up” on a reliable hosting service is worth the price for peace of mind.

But for tinkerers like me? This is exactly the kind of challenge we love. Exploring, breaking things, and figuring them out is half the fun.

It’s not just about having your own mail server, it’s about knowing exactly how it works and the satisfaction of building it yourself.

If you’ve ever considered hosting your own email, I’d love to hear how it went or what’s holding you back.

Good luck, and may your emails always land in the inbox! 😅

Abhishek Kumar