在CentOS上安裝郵件服務器可以通過以下步驟完成,這里以安裝Postfix和Dovecot為例:
sudo yum update
sudo yum install postfix dovecot cyrus-sasl
@
,記錄值為mail.yourdomain.com
,優先級為1。mail
,記錄值為服務器的公網IP地址。/etc/postfix/main.cf
文件,設置以下參數:myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
/etc/dovecot/dovecot.conf
文件,設置以下參數:protocols = imap pop3
mail_location = maildir:~/Maildir
sudo systemctl start postfix
sudo systemctl enable postfix
sudo systemctl start dovecot
sudo systemctl enable dovecot
sudo systemctl start saslauthd
sudo systemctl enable saslauthd
允許郵件服務相關的端口:
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --permanent --add-service=pop3
sudo firewall-cmd --permanent --add-service=imap
sudo firewall-cmd --reload
使用mailx
命令測試發送郵件:
echo "這是一封測試郵件" | mail -s "測試郵件" user@example.com
添加用戶并設置密碼:
sudo useradd -m user@example.com
sudo passwd user@example.com
使用郵件客戶端(如Outlook、Foxmail等)添加自建郵箱,配置SMTP服務器為mail.yourdomain.com
,端口為25。