在CentOS Stream 8上配置邮件服务,可以按照以下步骤进行:
Postfix是一个流行的邮件传输代理(MTA),用于发送和接收电子邮件。
sudo dnf install postfix
安装完成后,你需要配置Postfix。编辑主配置文件 /etc/postfix/main.cf:
sudo vi /etc/postfix/main.cf
进行以下基本配置:
myhostname: 设置你的主机名。
myhostname = mail.example.com
mydomain: 设置你的域名。
mydomain = example.com
myorigin: 设置邮件的来源域名。
myorigin = $mydomain
inet_interfaces: 设置监听的网络接口。
inet_interfaces = all
mydestination: 设置接收邮件的域名。
mydestination = $myhostname, localhost.$mydomain, $mydomain
mynetworks: 设置允许中继邮件的网络。
mynetworks = 127.0.0.0/8 [::1]/128
relay_domains: 设置允许中继的域名。
relay_domains = $mydestination
为了安全地发送邮件,你需要配置SASL认证。
sudo dnf install cyrus-sasl-plain cyrus-sasl-md5
编辑 /etc/postfix/main.cf 文件,添加以下行:
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
sudo touch /etc/postfix/sasl/sasl_passwd
sudo chmod 660 /etc/postfix/sasl/sasl_passwd
sudo vi /etc/postfix/sasl/sasl_passwd
添加你的SMTP认证信息:
[smtp.yourisp.com]:587 yourusername:yourpassword
sudo postmap /etc/postfix/sasl/sasl_passwd
确保你的防火墙允许SMTP流量(端口25, 465, 587)。
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --permanent --add-service=submission
sudo firewall-cmd --permanent --add-port=587/tcp
sudo firewall-cmd --reload
sudo systemctl start postfix
sudo systemctl enable postfix
你可以使用 telnet 或 nc 命令测试SMTP连接:
telnet localhost 25
你应该会看到类似以下的输出:
220 mail.example.com ESMTP Postfix
然后你可以按照SMTP协议的步骤发送一封测试邮件。
根据你的邮件客户端(如Outlook, Thunderbird等),配置SMTP和IMAP/POP3设置。
mail.example.commail.example.com通过以上步骤,你应该能够在CentOS Stream 8上成功配置邮件服务。