CentOS系統(tǒng)通過SMTP協(xié)議實現(xiàn)郵件發(fā)送全流程
環(huán)境準備與組件安裝
執(zhí)行以下命令安裝Postfix郵件服務(wù)組件:
sudo yum install postfix -y
啟動服務(wù)并設(shè)置開機自啟:
sudo systemctl start postfix
sudo systemctl enable postfix
Postfix主配置文件設(shè)置
修改/etc/postfix/main.cf配置文件:
myhostname = mail.yourdomain.com mydomain = yourdomain.com myorigin = $mydomain inet_protocols = ipv4 relayhost = [smtp.gmail.com]:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_use_tls = yes
郵件中繼認證配置
創(chuàng)建SASL認證文件:
sudo vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 username@gmail.com:app-password
生成數(shù)據(jù)庫文件并設(shè)置權(quán)限:
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd*
郵件發(fā)送功能測試
使用telnet進行SMTP協(xié)議測試:
telnet localhost 25
通過mailx工具發(fā)送測試郵件:
echo "測試內(nèi)容" | mail -s "主題" recipient@example.com
常見問題處理方案
防火墻配置
sudo firewall-cmd --permanent --add-service=smtp
sudo firewall-cmd --reload
日志排查方法
tail -f /var/log/maillog
TLS加密配置
在main.cf中補充配置:
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt smtp_tls_security_level = encrypt