静看光阴荏苒
不管不顾不问不说也不念

Postfix配置Gmail中继发信

之前配某环境的时候用到了这个,记录一下,系统是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 example@gmail.com:你的邮箱密码" > /etc/postfix/saslpasswd

使其生效:

postmap /etc/postfix/saslpasswd

重启postfix:

systemctl restart postfix

测试发信:

sendmail 1062951199@qq.com
From: admin@lala.im
Subject: Test mail
2333333333333333
.

可以没问题,就是会进垃圾箱罢了233:

如果碰到问题了,可以查看这个log:

tail -f /var/log/maillog
赞(2)
未经允许不得转载:荒岛 » Postfix配置Gmail中继发信
分享到: 更多 (0)

评论 4

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    前排支持博主
    (改了hosts之后方便多了)

    小东5年前 (2019-01-09) Google Chrome 73.0.3642.0 Google Chrome 73.0.3642.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 感谢资瓷。

      LALA5年前 (2019-01-10) Google Chrome 70.0.3538.110 Google Chrome 70.0.3538.110 Windows 10 x64 Edition Windows 10 x64 Edition回复

分享创造快乐

广告合作资源投稿