Tự Host Email Server Trên VPS 2026 - Postfix + Dovecot + Webmail. Thay Thế Google Workspace

📅 05/2026 · ⏱ 14 phút đọc · 🏷 Hướng Dẫn

Google Workspace 345K/tháng/user. Microsoft 365 160K/tháng. Với team 5 người → gần 2 triệu/tháng chỉ riêng email. Trong khi đó, VPS TrumVPS 80K/tháng có thể host email cho cả trăm account, không giới hạn. Bài viết này hướng dẫn tự build email server hoàn chỉnh với Postfix, Dovecot, Roundcube webmail trên VPS.

⚠️ Cảnh báo thực tế: Tự host email không dành cho tất cả mọi người. Email cần IP sạch (không blacklist), cấu hình SPF/DKIM/DMARC đúng, và duy trì liên tục. Nếu bạn cần email quan trọng (kinh doanh), cân nhắc dùng Google Workspace hoặc Hosting Netihot (có sẵn email). Bài này dành cho người muốn học và hiểu cách email hoạt động.

Tổng Quan: Email Server Gồm Những Gì?

Một email server hoàn chỉnh cần 3 thành phần:

Bước 1: Cài Postfix (SMTP Server)

apt update && apt install postfix -y
# Chọn: Internet Site → nhập domain

Cấu hình Postfix:

nano /etc/postfix/main.cf
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
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_auth_only = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
systemctl restart postfix

Bước 2: Cài Dovecot (IMAP/POP3 Server)

apt install dovecot-core dovecot-imapd dovecot-pop3d -y
nano /etc/dovecot/dovecot.conf
# Thêm: protocols = imap pop3
# Thêm: mail_location = maildir:~/Maildir
nano /etc/dovecot/conf.d/10-auth.conf
# auth_mechanisms = plain login
# disable_plaintext_auth = yes
nano /etc/dovecot/conf.d/10-master.conf
# Tìm service auth, thêm:
unix_listener /var/spool/postfix/private/auth {
  mode = 0660
  user = postfix
  group = postfix
}
systemctl restart dovecot

Bước 3: Cài SSL Cho Email

certbot certonly --nginx -d mail.yourdomain.com

Bước 4: Tạo User Email

adduser info
# Đặt password → user info@yourdomain.com đã sẵn sàng

Test gửi mail:

echo "Test email" | mail -s "Subject" your@gmail.com

Bước 5: Cấu Hình DNS — SPF, DKIM, DMARC

Đây là bước QUAN TRỌNG NHẤT. Nếu không cấu hình đúng, email của bạn sẽ vào spam.

RecordTypeValue
SPFTXTv=spf1 mx ~all
DKIMTXTCần generate key (xem hướng dẫn)
DMARCTXTv=DMARC1; p=none; rua=mailto:admin@yourdomain.com
MXMXmail.yourdomain.com (priority 10)

Bước 6: Cài Roundcube Webmail

apt install roundcube roundcube-mysql -y
# Chọn Yes → MySQL → nhập password

Cấu hình Nginx cho Roundcube:

nano /etc/nginx/sites-available/webmail.yourdomain.com
server {
    listen 443 ssl;
    server_name webmail.yourdomain.com;
    root /usr/share/roundcube;
    index index.php;
    location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; }
}

Truy cập https://webmail.yourdomain.com → đăng nhập → giao diện như Gmail!

So Sánh: Tự Host Email vs Dịch Vụ

Tiêu chíTự host (VPS 80K)Google WorkspaceHosting Email Netihot
Chi phí 5 user80K/tháng1.7M/tháng50K/tháng (kèm hosting)
Số accountKhông giới hạn5Theo gói
Setup2-4 tiếng10 phútCó sẵn
Bảo trìBạn tự loGoogle loNetihot lo
IP reputationBạn phải xây dựngGoogle IP (trust cao)Shared IP sạch
Vào spamCó thể nếu cấu hình saiHầu như khôngTỷ lệ thấp

Cần Email Chuyên Nghiệp Không Cần Tự Cài?

Hosting Netihot từ 10K/tháng — có sẵn email, webmail, spam filter, không cần cấu hình

🚀 Thuê Hosting Có Email