zh

在VPS上搭建邮件服务器:Postfix + Dovecot完整指南

自托管邮件服务器让您完全掌控电子邮件通信,无需依赖第三方服务商,实现真正的隐私保护。在离岸VPS上搭建邮件服务器结合了服务器控制权和地域隐私优势。本指南介绍使用Postfix(发送)和Dovecot(接收/存储)搭建功能完整邮件服务器的步骤。

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

前期准备:DNS配置

搭建邮件服务器前,必须正确配置DNS记录。以下记录缺一不可: 1. A记录:mail.example.com 指向服务器IP 2. MX记录:example.com 的邮件交换器为 mail.example.com(优先级10) 3. PTR记录(反向DNS):服务器IP反解为 mail.example.com - 重要:PTR记录需在服务器所在网络提供商处设置,AnubizHost提供此配置选项 4. SPF记录(TXT):v=spf1 mx ~all 5. DMARC记录(TXT):v=DMARC1; p=none; rua=mailto:[email protected] 确认DNS传播(可能需要几小时至24小时): dig MX example.com dig A mail.example.com host 服务器IP (验证PTR记录) DNS配置正确是邮件被正常接收(不进垃圾箱)的关键。

安装和配置Postfix

Postfix是Linux上最常用的邮件传输代理(MTA),负责邮件的发送和接收。 安装Postfix: DEBIAN_FRONTEND=noninteractive apt install postfix -y # 安装类型选择「Internet Site」,系统邮件名填写 example.com 主要配置文件 /etc/postfix/main.cf 关键设置: myhostname = mail.example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all inet_protocols = ipv4 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain home_mailbox = Maildir/ smtpd_tls_cert_file=/etc/letsencrypt/live/mail.example.com/fullchain.pem smtpd_tls_key_file=/etc/letsencrypt/live/mail.example.com/privkey.pem smtpd_use_tls=yes smtpd_tls_security_level=may 修改后重启Postfix:systemctl restart postfix

安装Dovecot和配置DKIM

Dovecot处理邮件的存储和用户通过IMAP/POP3协议的收取。 安装Dovecot: apt install dovecot-core dovecot-imapd dovecot-pop3d -y 关键配置文件: - /etc/dovecot/dovecot.conf:设置 protocols = imap pop3 - /etc/dovecot/conf.d/10-auth.conf:设置 disable_plaintext_auth = yes - /etc/dovecot/conf.d/10-mail.conf:设置 mail_location = maildir:~/Maildir 安装DKIM签名(OpenDKIM): apt install opendkim opendkim-tools -y opendkim-genkey -s mail -d example.com -D /etc/opendkim/keys/example.com/ 将生成的公钥(mail.txt文件内容)添加到DNS TXT记录: mail._domainkey.example.com TXT v=DKIM1; k=rsa; p=公钥内容 配置完成后,使用 mail-tester.com 测试邮件评分,目标10/10分。AnubizHost离岸VPS的IP段未被主流邮件服务商列入黑名单,有助于提高邮件送达率。

Why Anubiz Host

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

Ready to get started?

Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.

Anubiz Chat AI

Online