EmailLinux

Install Postfix Email Server on Ubuntu

Postfix, created by Wietse Venema, emerged as an alternative to the venerable Sendmail program. Its journey began at IBM Research, and after eight years at Google, Wietse continues to maintain the powerful Postfix email server. We’re going to install a Postfix email server on Ubuntu and configure it for multiple domains but first, what sets Postfix apart from other email servers like Exim?

  1. Speed and Efficiency: Postfix aims to be fast. Its architecture is designed for efficient message handling, making it suitable for high-traffic environments.
  2. Ease of Administration: Administrators appreciate Postfix’s straightforward configuration. Unlike Sendmail, which can be labyrinthine, Postfix offers a more intuitive setup.
  3. Security: Security is a top priority. Postfix emphasizes secure defaults, minimizing vulnerabilities. It has a Sendmail-like exterior but a completely different internal structure.
  4. Modularity: The core of Postfix comprises several server programs, each handling specific aspects of email delivery. These include the SMTP serverscheduleraddress rewriter, and local delivery server.

Whether you’re setting up a personal email server or managing enterprise communication, the Postfix email server remains a reliable choice. So, let’s get to it and install and configure Postfix for multiple domains in an Ubuntu VPS Server.

Required Infrastructure

To complete this guide and successfully High Availability for Postfix you will need a total of 4 servers running Ubuntu. We have created a bundle of 4 servers for users to purchase. These will be delivered with 100GB NAS storage already mounted to /nas in each backend server. Order Here or Contact Us.

  • 3x NVMe VPS Servers (Backends)
    • 50GB HDD
    • 4 vCore
    • 5GB Ram
    • 100GB NAS Storage (mounted at /nas in each server)
  • 1x Cloud VPS (Balancer)
    • 10GB HDD
    • 2 vCore
    • 2 GB Ram

Save 15% off each server with the promotional code BPIBQ69YH6

Articles In This Series

Configure DNS Records

Before starting, ensure the server(s) you want to use Postfix on have a fully qualified domain name (FQDM). That means your hostname should include at least two parts. Like mail.first2host.co.uk. We are configuring two email servers called m1.relay.gb.net and m2.relay.gb.net.

hostnamectl set-hostname m1.relay.gb.net

And next, ensure your hostname resolves to your VPS Server and you have set the correct A, AAAA and MX records,

A  m1.relay.gb.net IPv4 of server
A  m2.relay.gb.net IPv4 of server
AAAA m1.relay.gb.net IPv6 of server
AAAA m2.relay.gb.net IPv6 of server
MX relay.gb.net m1.relay.gb.net 10
MX relay.gb.net m2.relay.gb.net 20

Add Firewall Rules

Assuming you are using UFW as your firewall. Open port 25 only in your firewall for the moment. We will open more ports for Dovecot in the next article.

ufw allow 25

Install Postfix on Ubuntu Servers

So first to install Postfix on your Ubuntu server, use the commands below.

apt-get update && apt-get install postfix -y

Upon installation, you will be asked to choose from a few options. Assuming you want to send and receive email from this server choose Internet site and in the next box enter your domain name. We will deal with adding further domain names later on when we configure the Postfix email server.

Send Test Email

At this point, we can send a test email to ensure our firewall is configured correctly and that Postfix has been installed correctly. Postfix uses system accounts to send mail. Assuming you are currently the root user, you already have an email address on the domain you entered in the step above. In our case [email protected]. So, now send a quick test email.

echo "This is a test of the Postfix email server" | sendmail email@domain.com

This email will likely end up in a junk folder at the moment. So we will resolve that later on in this guide. For now, as long as you receive the test email you can continue. If you don’t receive the test email there are a few things to check. If you do not have any problems at this point you can skip the troubleshooting section.

Troubleshooting

Postfix and Sendmail log to the /var/log/mail.log file. But before digging into the logs ensure Postfix is listening on port 25.

 ss -lnpt | grep master

The output should be something similar to this. You’re just interested in the appended port. :25

LISTEN 0      100          0.0.0.0:25        0.0.0.0:*    users:(("master",pid=1383,fd=13))
LISTEN 0      100             [::]:25           [::]:*    users:(("master",pid=1383,fd=14))

So next look in the log file.

 tail -200 /var/log/mail.log

Connection Timed Out Postfix Error

In the Postfix log we noticed a connection timed-out error.

Mar  6 20:19:53 m1 postfix/smtp[2965]: connect to eur.olc.protection.outlook.com[104.47.30.97]:25: Connection timed out

This type of error is mainly caused by two things.

  • Port 25 is blocked at the router level or in the server’s firewall.
  • There is a routing misconfiguration.

As First2Host do not routinely block port 25 we suspected a routing error. So to troubleshoot this first try to telnet to port 25 on another service.

telnet alt1.gmail-smtp-in.l.google.com 25

If this works you know the firewall is not the issue. So we can dig deeper. Install tcptraceroute and trace the route to a mail server or the one with the connection timed out error.

apt install tcptraceroute

tcptraceroute litespeed.f2hcloud.com 25

In our environment, we can see from tcptraceroute that mail is trying to be sent via our private IP and not our public IP.

Selected device eth1, address 10.210.250.103, port 46393 for outgoing packets
Tracing the path to litespeed.f2hcloud.com (193.70.63.33) on TCP port 25 (smtp), 30 hops max
 1  10.210.250.1  0.068 ms  0.050 ms  0.053 ms
 2  * * *
 3  * * *

After correcting the routes. We can see our email sent.

Mar  6 20:26:41 m1 postfix/pickup[1385]: 39EDD471DF: uid=0 from=<root>
Mar  6 20:26:41 m1 postfix/cleanup[2845]: 39EDD471DF: message-id=<[email protected]>
Mar  6 20:26:41 m1 postfix/qmgr[1386]: 39EDD471DF: from=<[email protected]>, size=262, nrcpt=1 (queue active)
Mar  6 20:26:42 m1 postfix/smtp[2847]: 39EDD471DF: to=<[email protected]>, relay=eur.olc.protection.outlook.com[104.47.22.161]:25, delay=0.93, delays=0.01/0.01/0.58/0.33, dsn=2.6.0, status=sent (250 2.6.0 <[email protected]> [InternalId=66722316953746, Hostname=AS4PR02MB8408.eurprd02.prod.outlook.com] 7802 bytes in 0.088, 85.672 KB/sec Queued mail for delivery -> 250 2.1.5)
Mar  6 20:26:42 m1 postfix/qmgr[1386]: 39EDD471DF: removed

And over at Outlook, it was received.

Install configure Postfix email Server Ubuntu

So in this article, we have installed PostFix on an Ubuntu NVMe VPS Server and sent a test email. In the next article, we will Install Dovecot on our Postfix server with IMAP/SSL/TLS. See you on the other side.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button