Come hang with us on Discord and chat directly with the team!Discordtop-bar-close-icon

2024-08-29

How to Install Postfix on Ubuntu Server

tutorials
img

This guide will walk you through installing Postfix on the latest Ubuntu Server version. Postfix is a reliable, open-source mail transfer agent designed for sending and receiving emails on a server.

Step 1: Update Your System

It's essential to update your system before installing new software. Use the following command:

sudo apt-get update && sudo apt-get upgrade

This updates the package lists and installs any available updates for your system.

Step 2: Install Postfix

To install Postfix on your Ubuntu server, execute the following command:

sudo apt-get install postfix

This command downloads and installs the Postfix package with all necessary dependencies.

During installation, choose the "Internet site" option for the mail server configuration. Enter a fully qualified domain name (FQDN) that resolves to your server's IP address as the domain name.

Once installation is complete, verify the Postfix service status with:

sudo systemctl status postfix

If running, you will see output similar to:

● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2021-07-21 14:07:38 UTC; 1h 30min ago Main PID: 22583 (master) Tasks: 2 (limit: 2353) Memory: 3.2M CGroup: /system.slice/postfix.service ├─22583 /usr/lib/postfix/sbin/master -w └─22623 pickup -l -t unix -u

Step 3: Configure Postfix

Post-installation, you must configure Postfix. The main configuration file is located at /etc/postfix/main.cf.

Edit this file using your preferred text editor, such as nano or vim.

To configure Postfix for relaying outgoing emails through a third-party mail server, add these lines to main.cf:

relayhost = smtp.example.com smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous

This setup directs Postfix to forward all outgoing emails to smtp.example.com, using SASL authentication with credentials stored in /etc/postfix/sasl_passwd.

Step 4: Test Postfix

Ensure Postfix functions correctly by sending a test email from your server to an external address.

First, create a test message using a text editor, such as:

To: recipient@example.com Subject: Test Email This is a test email sent from my Ubuntu server.

Send the test message with:

cat test.txt | sendmail recipient@example.com

Replace recipient@example.com with a valid email address.

Verify the recipient's inbox to confirm delivery. Successful delivery indicates Postfix is operational.

Conclusion

You've learned how to install and configure Postfix on the latest Ubuntu Server version. With Postfix, you can manage email transmission and reception on your server and integrate it with other applications as needed.