Ludovic Frank - Freelance developer

Mailcow, when a cow manages your e-mails

ionicons-v5-k Ludovic Frank Jun 27, 2024
63 reads Level: intermediate

Hello, hello 🙂,

Thank you for clicking on this article, was it the cow photo that made you click?

So, yes... I see what you mean... I let loose on the image and on the title of this page... yes no, but it's summer, we're relaxing here 😛.

So, have you ever managed your own e-mail server? I have, several times in the past for different companies I've worked for...

Today, we're going to talk about a cow, but, not the one from interville (old man's reference...), but another one, who's in charge of managing e-mails... by the way you've seen how she does it on the picture of this article 😛.

My relationship with e-mail

Difficult beginnings

First of all, I'd like to tell you that e-mail isn't as simple as all that. SPF, DKIM... there's a lot you need to know before embarking on the adventure... in fact, with time and abuse, the protocol has evolved to prevent abuse and other spam.

As far as I'm concerned, the first time I played with e-mail servers was when I was a teenager, just for a change... Incidentally, I still have my "" domain, on which I always have an address lying around.

At the time I just wanted to understand how it all worked, I remember not understanding MX records at all, because a DNS MX record means "Mail Exchange", but it doesn't take an IP address as a value, but a domain name (an A or a CNAME).

Except that I didn't understand anything, "I want to send e-mails with", so for me the "A" in silentmail should be the e-mail server... well, no! 😛.

But, at the time, after having struggled for weeks, I had my e-mail server working, well almost... what's this "grey listing" stuff, no, but help me, it never stops actually! 🤣.

In production, in a company

In my professional life, before becoming 100% freelance, I went through a number of permanent contracts, and in particular, I was in charge of dev at the company, but not only that... in fact, I was in charge of the entire infrastructure. We had several bare-metal servers at different French hosting companies, OVH and Scaleway.

One day, looking at the invoice for the e-mail service provider we were using (I can't remember which one it was), we realized that the costs were skyrocketing pretty quickly, so they asked me if I couldn't come up with a more economical solution...

At the time, I didn't want to take on too much either, so we got Windows Server licenses and I discovered HMailServer, which was perfect, it did SMTP, which suited me and above all, everything was simple. As a reminder, in this company I managed everything... so I couldn't have 100% of my time monopolized by e-mails.

I used HMailServer mainly for the SMTP part (the part that takes care of sending and relaying e-mails), in fact there were 3 e-mail servers, and on the front, there was a HAProxy that routed e-mails to the different servers.

All this worked very well for years... and as you know today I'm no longer on permanent contract so I couldn't tell you if the company still uses this method 🙂.

What brings us to Mailcow today?

You have to remember that e-mail has become highly centralized, and I'd say that there are three big players taking the lion's share of the cake:

  • Google: with GSuite for businesses and Gmail for consumers.
  • Microsoft: With Microsoft 365 for businesses and Outlook (formerly Hotmail) for the general public.
  • Apple: with iCloud for home users.

So, the solution for most companies is to delegate this to Microsoft or Google and worry about other things...

Except that not long ago, I was asked to create an internal e-mail server for a client...

At first, knowing a little about all the problems of e-mail management, I wasn't too keen, but having a very good relationship with this customer and telling myself that if someone comes to ask me, it's because they really need it.

So, I put my nose back into this world, and saw iRedMail, which I already knew about, and other little things like MailInABox...

And then, while digging around, I came across an article about the German host "Hetzner". I know this host, because I had Team Fortress 2 servers with them when I was having fun coding plugins for the source engine (a lot has happened in my dev life, eh?).

I know how serious this host is, so if they're talking about Mailcow, I've got to take a look...

So I chose the cow as a base to meet the needs of this mission, then good, I like her, me, Marguerite 😁.

What is Mailcow?

I'd say that Mailcow is a grouping of well-known Linux software, plus they've added their own little in-house overlays to simplify the administration of it all...

For the benefit of Linux users reading this article, here are a few well-known programs you'll instantly recognize.

  • Postfix: The famous SMTP server that takes care of relaying e-mails, so when you log on to send an e-mail, it'll handle it for you.
  • Dovecot: The POP and IMAP server that stores your e-mails and folders and makes them accessible to you.
  • ClamAV: The open-source antivirus program that scans incoming and outgoing e-mails for viruses.
  • ACME: More of a protocol than a piece of software, but if you're using let's encrypt, then you're using this protocol to generate your SSL certificates.
  • SOGo: Roundcube used to be the open-source leader in webmail, but it's getting a bit old. SOGo offers an updated interface.

This list isn't exhaustive, but it gives you an idea of what we're talking about and, above all, makes our Linux friends feel right at home... 😛

Intensive use of Docker

To operate, our email-sending cow uses ready-to-use Docker containers, which simplifies everything.

However, even if you're using Docker with Mailcow, you should deploy your instance on a server that does just that. In the world of e-mail hosting, this is recommended, especially as your server's reverse DNS must match your server's name...

Install Mailcow on your server

Ready to let a cow manage your e-mail server? Let's get started.


Remember to keep your server up to date. In my case, I'm using Ubuntu Pro for 10 years' peace of mind.

The OVH case
If your server is with OVH, you'll need to obtain a "quesry key" from SpamHaus in order to be able to send requests to their services. In particular, when your server receives e-mails, it will check that the IP of the server sending the e-mail is not blacklisted.

On your server, you'll need Docker (the version supplied with Ubuntu 24.04 is very good) and Docker compose. Be careful with it, as you'll need at least version 2.0 for everything to work.

In the Ubuntu 24.04 repositories it's not this version that's available, of course you can use the official Docker repositories, but the problem is that you'll no longer benefit from the Ubuntu pro coverage I mentioned above.

In my case, I simply went looking for the static binary that I "put" on the system, for compose, it's not very important.

For those of you who are wondering "how will it lay on the system", it's very simple, I went looking for the binary on GitHub.

Then, I put it in a folder in my "$PATH", then a little chmod +x and that's it.


Following the documentation available here, you'll need toroot your machine with the "sudo su" command, for example.

Once you're root, they recommend going to "/opt", which works for me:

Once in our favorite mailcow directory, we run the config script.

At this stage, it will ask you for your server's host name. This is very important: it's not the domain that will send the e-mails, but the name of your server, for example "" and not

Also, it's during this step that it will ask you for your "Spamhaus" key, knowing that if you skip this step you'll be able to put it later in "mailcow.conf".

Launching MailCow for the first time

Once the configuration is complete, simply use the docker-compose command to launch MailCow for the first time:

Now all you have to do is wait a little and go to your MailCow administration interface, at the address HTTPS + your host name, your SSL certificate will be generated by Let's Encrypt.

By default, the login is admin and the password is "moohoo". Change it quickly, as there's a helper for this in your MailCow folder:

Once you're connected to your administration interface, take the time to rummage around, there are plenty of buttons 😁.

mailcow admin interface

DNS configuration

the interface is very clear and I'm not going to dwell on it too much, I'd just draw your attention to your DNS configuration, as this is one of the big problems with e-mail.

E-mail -> configuration, you'll be able to decide which domains will be managed by this e-mail server, nothing too complicated, just fill in the basic fields and you're all set.

Once you've added your domain, it's time to click on the DNS button.

Mailcow DNS configuration

Here I'd like to draw your attention to the "PTR" lines (no, this isn't the public test realms of World of Warcraft, yes, I did put WoW in my article), which represent your "reverse DNS".Don't try to add them in your domain name, but rather in the interface of the hosting provider who offers you your dedicated server or VPS.

Find out where to change the "reverse DNS", and make sure that this reverse is in line with your "host", which is why I don't recommend putting other services on the same machine.

Now all you have to do is create your e-mail addresses, the cow takes care of everything 😁.

Bonus: the MailCow API

And yes, we're still a dev here, and I was shown this just before I published this article, if you go to the "/api" URL of your MailCow instance, you'll see a nice Swagger interface...

Mailcow API

Ultra handy if you want to create your own interfaces for your users, e.g. a company can perfectly create an e-mail address for its new members with a simple HTTP request.

All you have to do is let your imagination run wild. To see the complete API documentation, click here.


Mailcow, a real steak! (Thanks Serge for the joke)

Configuring an e-mail server is basically a hellish task, with lots of notions to be grasped...

I particularly appreciated the fact that Mailcow takes you by the hand. If you don't know much about it, you can get by, the work on this part is remarkable, especially the DNS part...

As far as I'm concerned, I no longer host my e-mail servers, but MailCow has earned its place as number 1 whenever I need a mail server.

Have a great summer, I'll be back in September with lots of new articles, in the meantime, take care 🙂.