Caio Alonso learning github

Self-hosted email with EC2, Docker and Mailu

These are the steps I followed when setting up my own mail server.

Fire up an Ubuntu EC2 instance, then:

sudo apt update && sudo apt upgrade -y
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common git vim

Make sure these ports are open in your AWS security group:

Install Docker:

curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce

Install docker-compose:

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Install Mailu:

sudo mkdir /mailu
cd /mailu
sudo wget
sudo wget

Configure Mailu with sudo vim .env and set these entries:

Run it with:

sudo docker-compose up -d

Add an admin account with, replacing the uppercase strings:

sudo docker-compose run --rm admin python admin USERNAME DOMAIN PASSWORD

Antispam measures

Test it with mail-tester.


Add a TXT record to your nameserver. Name and content v=spf1 mx -all.


Go to your admin panel (https://DOMAIN/admin), then Mail domains > the Details icon and click Regenerate keys.

Copy the DNS DMARC entry line and do the same thing you did for the SPF. This time with name and the content is everything between quotes, in my case:

v=DMARC1; p=reject;;; adkim=s; aspf=s


On that same page do the same thing you did with DMARC, but using the DNS DKIM Entry.