To install a Postfix mail server on Linux, install the postfix package, set the hostname, domain and network options in /etc/postfix/main.cf, open the right ports and test with a real message. A minimal Postfix installation can send and receive mail for your domain; Dovecot, TLS and DKIM are added separately.
This guide uses Debian or Ubuntu commands, with the equivalent for RHEL-family systems noted where they differ. The example domain is example.com and the server hostname is mail.example.com. Replace both with your own.
Postfix is a mail transfer agent (MTA). It accepts mail over SMTP, queues it and delivers it locally or to another server. Before you install it, prepare these things:
mail.example.com with an A record pointing to the server.example.com that points to mail.example.com.Set the system hostname so Postfix reports the right name when it greets other servers.
On Debian and Ubuntu, install Postfix with apt. The installer asks which type of configuration you want.
Choose "Internet Site" when asked, and enter example.com as the system mail name. On RHEL, Rocky Linux and AlmaLinux, use sudo dnf install postfix and then sudo systemctl enable --now postfix. On Debian-based systems the service starts on its own.
Check that it is running and listening.
Postfix runs a master process that listens on port 25. The postconf command reads and writes configuration values, and it is safer than editing files by hand because it checks parameter names.
The main configuration file is /etc/postfix/main.cf. You only need a handful of parameters to get started. Set them with postconf -e, which edits the file for you.
What each setting does:
| Parameter | Purpose |
|---|---|
myhostname | The name Postfix announces in its SMTP greeting. It must match the PTR record. |
mydomain | Your mail domain. |
myorigin | The domain added to mail sent from local users. |
inet_interfaces | Which network interfaces accept connections. Use all to receive mail from the internet. |
inet_protocols | Use ipv4, or all once IPv6 DNS and reverse DNS are also correct. |
mydestination | Domains this server delivers locally instead of relaying. |
mynetworks | Clients allowed to relay through the server without authentication. Keep this to localhost. |
home_mailbox | Store mail in the Maildir format in each user's home directory. |
Never put a public range in mynetworks. Doing so turns your server into an open relay that spammers will find within hours, and your IP will end up on blocklists.
Reload Postfix after changes and check for mistakes.
postconf -n prints only the settings that differ from the defaults, which is a quick way to review your configuration.
Mail uses several ports. At this stage you need port 25 for server-to-server delivery. You will add submission and IMAP ports later.
Confirm your DNS from outside the server.
The first command should return 10 mail.example.com. or similar. The reverse lookup of your IP should return the same hostname. If any record is missing, other servers may reject your mail.
First, test local delivery. Create a user and send a message through the mail command, provided by the mailutils package on Debian and Ubuntu.
If you see a file in Maildir/new, local delivery works. Now test the SMTP conversation by hand with nc or telnet.
Next, test that the server refuses to relay for strangers. Try RCPT TO:<[email protected]> from an outside address. A correct server answers 554 5.7.1 Relay access denied. Finally, send a message from the server to an outside address and read the log to see what happened.
On RHEL-family systems and on newer Debian releases that use only the journal, read the log with sudo journalctl -u postfix -f.
When mail does not arrive, start with the queue and the log.
A line such as status=sent in the log means the remote server accepted the message. status=deferred shows a temporary failure with a reason, and status=bounced shows a permanent one. Common causes are a blocked port 25, a missing PTR record or a recipient server rejecting your IP.
No. Postfix sends and receives mail by itself. Dovecot adds IMAP and POP3 so that mail clients can read mailboxes.
The usual reasons are a missing reverse DNS record, a hostname that does not match it, no SPF or DKIM, or a cloud IP range that receivers distrust. Read the rejection text in /var/log/mail.log because it normally names the cause.
Both work. Postfix is the default on many distributions, has a modular design and clear documentation, which makes it a common first choice. Debian systems often ship Exim by default, so check what is already installed.
Try to relay from an outside host to an outside address. The server must refuse with Relay access denied. Keep mynetworks limited to localhost and your private network.
Install postfix, set myhostname, mydomain, mydestination and mynetworks with postconf -e, and open port 25. Make sure the A, MX and PTR records agree, then test local delivery, a manual SMTP session and an outbound message while watching the log. Keep the relay settings strict. Mailboxes with Dovecot, TLS, DKIM signing and relaying can be added afterwards.