本文最后更新于 227 天前,其中的信息可能已经有所发展或是发生改变。
1. Gmail开启SMTP功能
方式自行百度,此处不展示
2. 安装postfix
yum install postfix cyrus-sasl-sql cyrus-sasl-plain cyrus-sasl-lib mailx
3. 配置main.cf文件
vim /etc/postfix/main.cf //编辑main.cf文件
底部添加以下内容
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_sasl_tls_security_options = noanonymous
smtp_tls_security_level = may
4. 新建邮箱认证配置文件
vim /etc/postfix/sasl_passwd
并添加以下内容
[smtp.gmail.com]:587 [email protected]:wixhljacufesesws
前半段为smtp服务器地址及端口,后半部分为你的邮箱地址及密码(SMTP授权码)
修复权限并更新 postfix 配置以使用 sasl_passwd 文件:
chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
重启postfix saslauthd
systemctl restart postfix
systemctl restart saslauthd
5. 邮件测试
echo "Test mail from postfix" | mail -s "Test Postfix" [email protected]
此时你可以收到一封
主题为 Test Postifx;内容为 Test mail from postfix 的邮件