原文地址:https://lala.im/4727.html,請支持原作者!該處僅作轉載。
之前配某环境的时候用到了这个,记录一下,系统是CentOS7X64。理论上还支持其他SMTP服务器,不一定非要是Gmail,如果是国内机器Gmail是肯定用不了的。
首先安装Postfix:
yum -y install postfix
启动和设置开机启动:
systemctl start postfix
systemctl enable postfix
安装cyrus-sasl,不然SMTP无法成功认证:
yum -y install cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain
备份一下默认的配置文件:
cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
编辑配置文件:
vi /etc/postfix/main.cf
CentOS7安装的postfix默认的这个配置文件内的参数基本上都是注释掉的,所以我们可以直接把需要用到的参数加到文件的末尾:
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
新建一个saslpasswd文件:
echo "[smtp.gmail.com]:587 [email protected]:你的邮箱密码" > /etc/postfix/saslpasswd
使其生效:
postmap /etc/postfix/saslpasswd
重启postfix:
systemctl restart postfix
测试发信:
sendmail [email protected]
From: [email protected]
Subject: Test mail
2333333333333333
.
可以没问题,就是会进垃圾箱罢了233:
如果碰到问题了,可以查看这个log:
tail -f /var/log/maillog