Step-by-Step Guide to Hosting Emails on mail.yourdomain.com Using Postfix on Ubuntu
How to Install and Configure Postfix on Ubuntu to Use a Subdomain for Emails
Table of Content
Postfix is a free, open-source Mail Transfer Agent (MTA) (Mail Server for short) designed for sending and receiving emails. It was created as an alternative to the older Sendmail and is known for its security, ease of use, and flexibility.
Postfix is widely adopted for handling mail services on Linux servers due to its efficiency and simplicity.
If you need to host your own email server on Ubuntu, Postfix is one of the best choices. In this guide, we'll configure Postfix to use the subdomain mail.yourdomain.com
and set up email addresses like [email protected]
.
Why Do You Need Postfix?
- Self-Hosted Email: Control your own email infrastructure instead of relying on third-party providers.
- Privacy: Enhanced privacy by keeping your emails on your server.
- Cost-Effective: Free and open-source, eliminating subscription costs.
- Flexibility: Highly configurable to fit different needs (personal, business, etc.).
Prerequisites
Before starting, ensure you have the following:
- Ubuntu Server 20.04/22.04 (or later).
- A registered domain name (e.g.,
yourdomain.com
). - Subdomain setup: Create an
A
record formail.yourdomain.com
pointing to your server's IP address. - SSH Access to your server.
- Basic Knowledge of Linux commands.
Step 1: Update Your System
Log in to your server via SSH and update the package lists:
sudo apt update && sudo apt upgrade -y
Step 2: Install Postfix
Install Postfix using the apt
package manager:
sudo apt install postfix -y
During installation, the configuration wizard will prompt you with options:
- General Type of Mail Configuration: Choose
Internet Site
. - System Mail Name: Enter your primary domain name, e.g.,
yourdomain.com
.
Note: We’ll configure the subdomain mail.yourdomain.com
manually later.
Step 3: Configure Postfix
Open the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Key Configurations
Update or add the following lines: