Home

Postfix: Setting Up a Mail Server

Server
Difficulty: Advanced
3 min read

Detailed tutorial to install and configure Postfix, an open-source Mail Transfer Agent (MTA), on Linux.

Back to tutorials

Key takeaways

  • Postfix is an MTA: it moves mail over SMTP, it does not serve mailboxes to clients. To read your messages from Thunderbird or Outlook you have to pair it with Dovecot (IMAP/POP3).
  • DNS drives everything: an A record for mail.example.com pointing at the server's static IP, and an MX record pointing at that A record. During package installation, pick Internet Site and enter your domain as the system mail name.
  • In /etc/postfix/main.cf, myhostname is the server's fully qualified hostname, mydestination is the list of domains it accepts final delivery for, and home_mailbox = Maildir/ sets the mailbox format. Run systemctl reload postfix after every change.
  • The format declared on the Postfix side (home_mailbox = Maildir/) must match Dovecot exactly (mail_location = maildir:~/Maildir in /etc/dovecot/conf.d/10-mail.conf), otherwise messages land on disk but stay invisible over IMAP.
  • Encryption relies on a Let's Encrypt certificate (certbot certonly --standalone -d mail.example.com) referenced in both main.cf and 10-ssl.conf; smtpd_tls_auth_only=yes forbids authentication in the clear. Deliverability comes next: SPF, DKIM and DMARC.
What is Postfix?
Postfix is an open-source Mail Transfer Agent (MTA). It is the software that runs on a server to send and receive emails using the SMTP protocol. It is known for its security, its speed and its ease of configuration compared to older alternatives such as Sendmail.

Why run your own mail server?

  • Full control: You own your data, your emails are not stored with a third party.
  • Unlimited addresses: Create as many addresses, aliases and forwards as you want for your domain.
  • Learning: It is an excellent project for understanding how the Internet works.

Warning: Running a mail server comes with significant responsibilities, particularly regarding security (fighting spam) and deliverability (not being flagged as a spammer).

Prerequisites

  • A Linux server (Ubuntu/Debian) with a static IP address.
  • A domain name (e.g. `example.com`) whose DNS records you can modify.
  • An `A` DNS record pointing to your server's IP (e.g. `mail.example.com`).
  • An `MX` DNS record pointing to your `A` record (e.g. `MX @ mail.example.com`).

Premium Content

This advanced tutorial is reserved for premium members.

9,90€ / month
  • All advanced tutorials
  • New content every week
  • Progress tracking
  • Cancel anytime
MR

Written by

Morgann Riu

Cybersecurity and Linux administration expert. I share my knowledge through free tutorials and training to help system administrators and developers secure their infrastructures.

Frequently asked questions

My emails leave without any error but land in spam, what should I do?
A server that sends and receives correctly only does half the job. You need to publish an SPF DNS record listing the servers allowed to send for your domain, sign messages with DKIM (a cryptographic signature added to every email), then declare a DMARC policy telling receiving servers what to do when SPF or DKIM fail. Without those three records, most large providers will file your messages as junk no matter how clean your Postfix configuration is.
Is Postfix enough to fetch mail from Thunderbird or Outlook?
No. Postfix is a transfer agent: it accepts mail over SMTP and drops it into local mailboxes, but it exposes neither IMAP nor POP3. You need a retrieval server, in practice Dovecot (the dovecot-imapd and dovecot-pop3d packages), configured for the same mailbox format as Postfix. The two services are complementary, not competing.
The logs show the mail was delivered but the IMAP mailbox stays empty, why?
It is almost always a format mismatch between the two services. Postfix writes wherever home_mailbox in main.cf points, while Dovecot reads wherever mail_location in /etc/dovecot/conf.d/10-mail.conf points. If Postfix delivers in mbox while Dovecot expects Maildir, the message genuinely exists on disk but cannot be found over IMAP. Line up home_mailbox = Maildir/ with mail_location = maildir:~/Maildir, then restart both services.
certbot certonly --standalone fails, what is going wrong?
The --standalone mode spins up its own temporary web server to answer the challenge, so it needs port 80 free and reachable from the Internet. Stop whatever web server is holding that port for the duration of the request, and open it on the firewall. Also make sure the name passed to -d (for example mail.example.com) publicly resolves to this server's IP, otherwise validation cannot complete.
How do I confirm an email actually went out and trace its path?
Install the mailutils package and send a test message from the command line, for example echo "body" | mail -s "Subject" [email protected] to an external mailbox. Then follow /var/log/mail.log: every step is recorded there, from Postfix accepting the message to the delivery attempt against the remote server and its return code. That file is where you will see a rejection, a deferral or a TLS error.

Share this tutorial

Did you enjoy this article?

Was this article helpful?

Thanks for your feedback!

Comments

Recommended for you

In-depth article on the topic

Checklist Sécurité Linux

30 points essentiels pour sécuriser un serveur Linux. Recevez aussi les nouveaux tutoriels par email.

Pas de spam. Désabonnement en 1 clic.

↑