📞 🇺🇸 +1 361 304 4309 📞 🇮🇳 +91 76769 02281 ✉️ [email protected]
Email Servers

How to Set Up Postfix and Dovecot Mail Server on Ubuntu

How to Set Up Postfix and Dovecot Mail Server on Ubuntu

Running your own mail server gives you full control over email delivery, privacy and cost. This guide sets up a complete mail stack with Postfix for sending and Dovecot for receiving.

Prerequisites

Step 1 — Set Hostname

sudo hostnamectl set-hostname mail.yourdomain.com
echo "YOUR_IP mail.yourdomain.com mail" | sudo tee -a /etc/hosts

Step 2 — Install Postfix

sudo apt update
sudo apt install postfix -y

During installation select Internet Site and enter your domain name.

Step 3 — Configure Postfix

sudo nano /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost =
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/

# TLS
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
smtpd_use_tls = yes
smtpd_tls_security_level = may
smtp_tls_security_level = may

Step 4 — Install Dovecot

sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y

Step 5 — Configure Dovecot

sudo nano /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
mail_location = maildir:~/Maildir
disable_plaintext_auth = yes
ssl = required
ssl_cert = 

Step 6 — Create Mail User

sudo adduser mailuser
sudo mkdir -p /home/mailuser/Maildir/{cur,new,tmp}
sudo chown -R mailuser:mailuser /home/mailuser/Maildir

Step 7 — Configure DNS Records

# MX record
yourdomain.com MX 10 mail.yourdomain.com

# A record for mail server
mail.yourdomain.com A YOUR_SERVER_IP

# SPF record
yourdomain.com TXT "v=spf1 mx ~all"

Step 8 — Start Services

sudo systemctl enable postfix dovecot --now
sudo systemctl status postfix dovecot

Step 9 — Test Mail Server

# Send test email
echo "Test email body" | mail -s "Test Subject" [email protected]

# Check mail logs
sudo tail -f /var/log/mail.log

Conclusion

Your mail server is now sending and receiving email. For professional managed mail server support including anti-spam, DKIM and monitoring, contact our team.

Share this guide:
🛠️ Need Expert Help?

Don't want to do this yourself?

Our certified engineers implement this for you — correctly, securely, and within hours. Available 24/7 with 15-minute emergency response.

  • ✅ 19+ years experience
  • ✅ 60+ certified engineers
  • ✅ 1,600+ servers managed
  • ✅ 40+ countries served
  • ✅ Plans from $49/mo

Get Expert Help — Free Consultation

We respond within 4 hours · No commitment required

Please enter your name and a valid email.

No spam. Privacy Policy

Comments