setting up an email server on Ubuntu is a great way to manage your own business or project emails (e.g., yourname@yourdomain.com).
Below I’ll show you a clear step-by-step guide for setting up a complete email server using Postfix (SMTP) and Dovecot (IMAP/POP3) — the most common and stable open-source combo.
🧩 1. Requirements
Before starting, make sure you have:
-
🖥️ Ubuntu Server (22.04 or newer recommended)
-
🌐 A domain name (e.g.,
example.com) -
📮 DNS records:
-
A record → points
mail.example.com→ your server’s IP -
MX record → points
example.com→mail.example.com -
PTR record (reverse DNS) → your IP →
mail.example.com
-
-
🔒 Optional but recommended:
-
SPF, DKIM, and DMARC records for better deliverability
-
A valid SSL certificate (from Let’s Encrypt)
-
⚙️ 2. Install Required Packages
First, update your system:
Then install Postfix and Dovecot:
During Postfix installation, you’ll be prompted:
-
Mail configuration type: choose
Internet Site -
System mail name: enter your domain name (e.g.,
example.com)
📨 3. Configure Postfix (SMTP)
Open the main configuration file:
Make sure it contains (adjust your domain):
Save and exit (Ctrl+O, Enter, Ctrl+X), then restart Postfix:
📥 4. Configure Dovecot (IMAP/POP3)
Edit the main config:
Add or check:
Now enable Maildir format:
Find this line:
Uncomment it (remove the # if needed).
Restart Dovecot:
👤 5. Create a Mail User
Create a user account for your email:
Then create their mail directory:
🔐 6. (Optional) Enable SSL/TLS Encryption
Install Let’s Encrypt:
Then configure Postfix and Dovecot to use the certificate:
-
Postfix SSL config:
/etc/postfix/main.cf -
Dovecot SSL config:
/etc/dovecot/conf.d/10-ssl.conf
🧪 7. Test Your Email Server
Send a test email:
Check mail log:
Access mailbox via IMAP:
Use an email client (Thunderbird, Outlook, etc.)
-
Incoming mail (IMAP):
mail.example.com, Port 993 (SSL) -
Outgoing mail (SMTP):
mail.example.com, Port 587 (TLS) -
Username: your Linux username
-
Password: your user password
🧱 8. (Optional but Recommended)
For better email deliverability:
-
Add SPF, DKIM, and DMARC DNS records
-
Use opendkim and opendmarc packages
-
Install SpamAssassin for spam filtering
✅ Summary
| Component | Software | Function |
|---|---|---|
| SMTP | Postfix | Sends outgoing mail |
| IMAP/POP3 | Dovecot | Receives and syncs mail |
| Security | Let’s Encrypt + TLS | Encrypts connections |
| Anti-Spam | SpamAssassin (optional) | Filters junk mail |
| DNS | A, MX, SPF, DKIM, DMARC | Enables domain-based email delivery |