在CentOS上配置邮件服务器,你可以选择使用Postfix作为MTA(邮件传输代理),Dovecot作为MDA(邮件交付代理)。以下是配置步骤:
首先,更新你的系统包列表并安装Postfix和Dovecot:
sudo yum update -y
sudo yum install postfix dovecot -y
编辑Postfix的主配置文件 /etc/postfix/main.cf
:
sudo vi /etc/postfix/main.cf
根据你的需求进行配置。以下是一个基本的配置示例:
# 设置系统邮件名称
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
# 设置邮件服务器的IP地址
inet_interfaces = all
# 设置SMTP认证
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
# 设置邮件传输代理
relayhost =
# 启用TLS
smtpd_tls_cert_file = /etc/pki/tls/certs/localhost.crt
smtpd_tls_key_file = /etc/pki/tls/private/localhost.key
smtpd_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
# 设置日志级别
debug_peer_level = 2
保存并退出编辑器。
编辑Dovecot的主配置文件 /etc/dovecot/dovecot.conf
:
sudo vi /etc/dovecot/dovecot.conf
确保以下配置项存在:
protocols = imap pop3
listen = *
保存并退出编辑器。
编辑Dovecot的SASL认证配置文件 /etc/dovecot/conf.d/10-auth.conf
:
sudo vi /etc/dovecot/conf.d/10-auth.conf
确保以下配置项存在:
disable_plaintext_auth = no
auth_mechanisms = plain login
保存并退出编辑器。
编辑Dovecot的IMAP和POP3配置文件 /etc/dovecot/conf.d/10-mail.conf
:
sudo vi /etc/dovecot/conf.d/10-mail.conf
确保以下配置项存在:
mail_location = maildir:~/Maildir
保存并退出编辑器。
启动Postfix和Dovecot服务,并设置它们在系统启动时自动启动:
sudo systemctl start postfix dovecot
sudo systemctl enable postfix dovecot
确保你的防火墙允许SMTP(端口25)、IMAP(端口143)和POP3(端口110)流量:
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --permanent --add-service=imap
sudo firewall-cmd --permanent --add-service=pop3
sudo firewall-cmd --reload
你可以使用 telnet
或 openssl
命令测试SMTP连接:
telnet localhost 25
或者使用 openssl
:
openssl s_client -connect localhost:25
如果一切配置正确,你应该能够看到SMTP服务器的欢迎信息。
确保你的DNS记录中包含MX记录,指向你的邮件服务器地址。例如:
example.com. IN MX 10 mail.example.com.
完成以上步骤后,你的CentOS邮件服务器应该已经配置好了。你可以开始发送和接收邮件了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:如何配置CentOS邮件服务器