So, I wanted to host my own mail server. Not Gmail, not Proton, just me, my server, and full control. The goal: get SMTP with TLS (SMTPS), IMAP with TLS (IMAPS), and a catch-all address to receive emails for anything@mydomain. Of course, nothing went as planned, but hey – here’s the full setup that’s now working like a charm.
This post is part reminder-to-myself, part tutorial, and 100% personal.Let’s go.
Context
- Distro: Debian
- Host: LXC container on Proxmox
- Domain:
mydomain.org(managed on Cloudflare) - Mail server hostname: mail.mydomain.org
- Only one user for now:
contact
Groups for the contact user:
DNS Configuration (Cloudflare)
Here’s what I set in Cloudflare for the domain:
| Type | Name | Value |
|---|---|---|
| MX | @ | mail.mydomain.org |
| A | mail |
< Your public IP > |
| TXT | @ | v=spf1 ipv4:< Your public IP > a mx ~all |
| TXT | mail._domainkey | DKIM (don't set it yet, see note below) |
| TXT | _dmarc | v=DMARC1; p=quarantaine; aspf=r; sp=none |
⚠️ Important: Make sure the A record for
mail.mydomain.orgis not proxied through Cloudflare (gray cloud).Otherwise, SMTP won’t work properly.
About DKIM: I struggled here. Just follow the video I used (this one). Don't try to outsmart it, don’t ask ChatGPT about DKIM – it will send you in circles.
Postfix Configuration
Base install:
Here’s my postconf -n output:
And the /etc/postfix/virtual file:
This sets up the catch-all: every email sent to anything@mydomain.org ends up in contact’s inbox.
Dovecot Configuration
/etc/dovecot/dovecot.conf
Just add this line at the end:
/etc/dovecot/conf.d/10-auth.conf
/etc/dovecot/conf.d/10-master.conf just add these lines in service auth:
This part is what allows Postfix to ask Dovecot if credentials are OK.
User Setup
No special setup, just set your password and ENTER !
Certificates with Let’s Encrypt
I followed this:
Of course, redirect the port 80/TCP from your firewall to your server.
Certs go here: /etc/letsencrypt/live/mail.mydomain.org/
Testing (iPhone mail app)
IMAP:
mail.mydomain.org- Port
993 - SSL/TLS
Login: contact
Password: The one you defined.
SMTP:
mail.mydomain.org- Port
587 - SSL/TLS
Trials & Errors
-
First I tried ChatGPT. Mistake. It gave me a bunch of half-working suggestions and configs that made no sense.
-
Then I found this random YouTube video.
-
That guy explained it way better. I just followed along and then adjusted the stuff that didn’t fit my setup.
-
Eventually, I talked to ChatGPT again – but only for double-checking specific configs.
-
DKIM was a pain. Don’t try to set anything in DNS manually, the guy in the video shows the right way with OpenDKIM.
It's not necessarily intuitive, there are traps everywhere, but when it works, it's your own mailbox.
Now I get all the *@mydomain.org mail in my inbox. I can make as many aliases as I want, create addresses for each service, and even track leaks if my address gets spammed.
Done. Mail works. Gmail who?
Made by h0ag.