First, set up the following DNS records in your domain management panel:
dig +short chat.example.org A
Madmail supports four TLS modes. The table below shows the differences:
| Mode | Challenge | DNS API | Port 80 | Use Case |
|---|---|---|---|---|
| autocert | HTTP-01 | No | Required | Production server |
| acme | DNS-01 | Yes | No | Server behind firewall |
| file | โ | โ | โ | Existing certificate |
| self_signed | โ | โ | โ | Testing & development |
sudo maddy install \ --domain chat.example.org \ --tls-mode autocert \ --acme-email admin@example.org \ --enable-chatmail \ --non-interactive
How it works:
/var/lib/maddy/autocert/In the configuration file (maddy.conf):
tls {
loader autocert {
hostname chat.example.org
email admin@example.org
cache_dir /var/lib/maddy/autocert
agreed
}
}
sudo maddy install \ --domain chat.example.org \ --tls-mode acme \ --acme-email admin@example.org \ --acme-dns-provider cloudflare \ --acme-dns-token "YOUR_CLOUDFLARE_TOKEN" \ --enable-chatmail \ --non-interactive
Supported DNS providers: cloudflare, gandi,
digitalocean, vultr, hetzner, route53
sudo maddy install \ --domain chat.example.org \ --tls-mode file \ --cert-path /etc/letsencrypt/live/chat.example.org/fullchain.pem \ --key-path /etc/letsencrypt/live/chat.example.org/privkey.pem \ --enable-chatmail
Configuration file format:
sudo maddy install \ --simple --ip YOUR_SERVER_IP \ --tls-mode self_signed \ --turn-off-tls
Certificates are stored in /var/lib/maddy/certs/ and reused on subsequent restarts.
After setup, verify your certificate with this command:
Expected output:
sudo rm /var/lib/maddy/certs/fullchain.pem /var/lib/maddy/certs/privkey.pem
sudo maddy install \ --domain chat.example.org \ --tls-mode autocert \ --acme-email admin@example.org \ --enable-chatmail \ --non-interactive
sudo systemctl restart maddy
Run the following commands to fix file ownership and permissions:
sudo chown root:maddy /path/to/cert.pem /path/to/key.pem sudo chmod 640 /path/to/cert.pem /path/to/key.pem
600 permissions (owner only)640 permissions (owner + group)700 permissions (owner only)