// blog

How to Install and Configure Postfix on a Linux VPS: Complete Guide to Your Own Mail Server

August 25, 2026 · by Alex M.

How to Install and Configure Postfix on a Linux VPS: Complete Guide to Your Own Mail Server

If you run a website, a web application, or an online store, transactional emails — order confirmations, notifications, password resets — are essential. Relying on external email services can be limiting and costly. The solution? Your own mail server, built with Postfix, the most popular Mail Transfer Agent (MTA) in the Linux world.

In this guide you'll learn how to install and configure Postfix on a NVMe VPS or SSD VPS, step by step — from installation through to testing email delivery.


What Is Postfix and Why Use It?

Postfix is an open-source SMTP server — fast, secure, and easy to configure. It accepts messages from applications or users and delivers them either locally or over the internet via the SMTP protocol.

Key advantages:
- Easy to install on any Linux distribution (Ubuntu, Debian, CentOS, AlmaLinux)
- High performance even on limited resources
- Native integration with Dovecot, SpamAssassin, OpenDKIM
- Large community and excellent documentation

⚠️ Important note: This guide covers configuring Postfix as an outbound MTA only. A full mail server (with mailboxes, IMAP) also requires Dovecot, which will be covered in a separate article.


Prerequisites

Before you begin, make sure you have:

  • A Linux VPS running Ubuntu 22.04 or Debian 12 (recommended)
  • Root or sudo access
  • A registered domain with access to the DNS zone
  • Port 25 unblocked by your hosting provider (important — some providers block it by default)
  • A valid SSL certificate for your domain (for TLS)

Check whether port 25 is open:

telnet smtp.gmail.com 25

If the connection succeeds, you're ready to proceed.


Step 1: Update the System and Install Postfix

sudo apt update && sudo apt upgrade -y
sudo apt install postfix -y

During installation, an interactive menu will appear. Select:
- Configuration type: Internet Site
- System mail name: your domain (e.g. example.com)

After installation, verify the status:

sudo systemctl status postfix

You should see active (running).


Step 2: Configuring the Main File — main.cf

The main configuration file is located at /etc/postfix/main.cf. Open it with a text editor:

sudo nano /etc/postfix/main.cf

Ensure the following directives are set correctly:

# Server identity
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain

# Listening interfaces
inet_interfaces = all
inet_protocols = ipv4

# Local destinations
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# Trusted networks
mynetworks = 127.0.0.0/8

# Mailbox format
home_mailbox = Maildir/

# Limits
message_size_limit = 52428800

Save the file (Ctrl+O, Enter, Ctrl+X) and restart Postfix:

sudo systemctl restart postfix

Step 3: Configuring TLS for Secure Connections

Without TLS, your emails can be intercepted in transit. If you already have an SSL certificate (obtained with Let's Encrypt or from CLIQHOST), add the following to main.cf:

# TLS for incoming connections
smtpd_tls_cert_file = /etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/example.com/privkey.pem
smtpd_use_tls = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

# TLS for outgoing connections
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_tls_security_level = may

Restart Postfix again after these changes:

sudo systemctl restart postfix

Step 4: Configuring DNS Records (SPF, DKIM, DMARC)

Without correct DNS records, your emails will land in spam. Three types of records are required:

SPF (Sender Policy Framework)

Add a TXT record to your domain:

name: @  type: TXT  value: "v=spf1 ip4:YOUR_SERVER_IP mx ~all"

Replace YOUR_SERVER_IP with your VPS IP address.

DKIM (DomainKeys Identified Mail)

Install OpenDKIM:

sudo apt install opendkim opendkim-tools -y

Generate the keys:

sudo mkdir -p /etc/opendkim/keys/example.com
sudo opendkim-genkey -b 2048 -d example.com -D /etc/opendkim/keys/example.com -s mail -v
sudo chown -R opendkim:opendkim /etc/opendkim/keys/

The contents of the mail.txt file from the generated directory must be added as a TXT record in DNS:

name: mail._domainkey.example.com  type: TXT  value: (contents of mail.txt)

Configure /etc/opendkim.conf and link OpenDKIM to Postfix via socket:

MilterProtocol   6
Syslog           yes
UMask            002

Domain           example.com
KeyFile          /etc/opendkim/keys/example.com/mail.private
Selector         mail

In main.cf, add:

milter_protocol = 6
milter_default_action = accept
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891

Restart both services:

sudo systemctl restart opendkim postfix

DMARC

Add a TXT record:

name: _dmarc  type: TXT  value: "v=DMARC1; p=quarantine; rua=mailto:[email protected]"

Step 5: Testing the Postfix Server

Send a test email from the command line:

sudo apt install mailutils -y
echo "This is a test email" | mail -s "Postfix Test" [email protected]

Check the log for errors:

sudo tail -f /var/log/mail.log

Look for the line status=sent — if it appears, the email was sent successfully.

Check your deliverability score:

Use mail-tester.com — send an email to the address generated by the site and you'll receive a score from 1 to 10. Aim for at least 8/10.


Common Problems and Solutions

Problem Likely Cause Solution
Emails land in spam SPF/DKIM/DMARC missing or wrong Reconfigure DNS records
Connection refused on port 25 Port blocked by provider Contact CLIQHOST support
Relay access denied mynetworks too restrictive Add the application IP to mynetworks
TLS handshake failed Expired or misconfigured SSL cert Renew or verify the certificate

Security Tips for Postfix

An unprotected mail server quickly becomes a spam source. A few essential measures:

  1. Disable open relaymynetworks should only contain your trusted networks
  2. Limit sending rate — use smtpd_client_message_rate_limit
  3. Use Fail2Ban to block IPs attempting repeated authentication failures
  4. Monitor logs daily/var/log/mail.log and /var/log/mail.err
  5. Keep Postfix updated regularly: sudo apt upgrade postfix

If you need a managed solution, server management services from CLIQHOST include configuration and monitoring of mail servers. For heavier workloads, our managed dedicated servers offer the ideal foundation.


Conclusion

Postfix is an excellent choice for sending email from your own Linux server. With the correct configuration of TLS, SPF, DKIM, and DMARC, your messages will land in the inbox — not in spam.

The keys to success are:
- A VPS with a clean IP (no spam history)
- Complete and accurate DNS records
- Continuous log monitoring

If you're looking for a stable infrastructure on which to run Postfix, explore NVMe VPS plans from CLIQHOST — high performance, clean IPs, and technical support available around the clock. For any additional questions, our team is always ready to help.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău