What is Postfix?
Postfix is a free, open-source Mail Transfer Agent (MTA) that routes and delivers electronic mail. It is renowned for its speed, security, and ease of administration compared to older alternatives like Sendmail. Setting up Postfix on an Ubuntu server allows your applications to send automated notification emails or serves as the foundation for a full-scale email hosting solution.
Step 1: Update Packages and Install Postfix
Before installing new software, it is best practice to update your local package index. Open your terminal and run:
sudo apt update
Next, install the postfix package along with mailutils, which provides helpful command-line utilities for testing:
sudo apt install postfix mailutils -y
Step 2: Navigate the Initial Setup Wizard
During the installation, a text-based configuration wizard will appear on your screen. You will be prompted to select a general type of mail configuration. Use the arrow keys to select Internet Site and press Enter.
Next, you will be asked for the System mail name. This should be a fully qualified domain name (FQDN) that resolves to your server’s IP address (e.g., mail.yourdomain.com). Enter the domain and press Enter to finish the installation.
Step 3: Modify the Main Configuration File
The primary configuration file for Postfix is located at /etc/postfix/main.cf. Open it using a text editor:
sudo nano /etc/postfix/main.cf
Ensure the following directives are configured correctly for your environment:
myhostname: Should match your FQDN.mydestination: Lists the domains that this machine will deliver locally, instead of forwarding to another machine.inet_interfaces: Set toallto listen on all network interfaces, orloopback-onlyif you only want local applications to use the mail server.
Step 4: Restart the Postfix Service
After making any changes to the main.cf file, you must restart the Postfix service to apply them:
sudo systemctl restart postfix
Also, ensure the service is enabled to start automatically on boot:
sudo systemctl enable postfix
Step 5: Test Mail Delivery
You can quickly test if your Postfix installation can successfully send emails to the outside world using the mail command provided by the mailutils package. Run the following command, replacing the email address with your own personal address:
echo "This is a test email from Postfix" | mail -s "Postfix Test" [email protected]
Check your inbox (and your spam folder). If the email arrives, your Postfix server is correctly configured and operational for outbound routing.