Profix 搭建smtp邮件转发
有图好说话
mail client内部网络无法连接外网,通过mail relayserver发送邮件
本测试使用centos 7版本
mail relayserver:192.168.160.132
安装postfix
默认系统已经安装postfix,如果没装则可以按照一下方式安装
yum install -y postfix
服务管理
systemctl start postfix #启动
配置文件
/etc/postfix/main.cf
编辑配置文件
vim /etc/postfix/main.cf
inet_interfaces = all #监听端口
inet_protocols = ipv4 #使用IPV4进行通讯
relayhost = [smtp.163.com]:25 #转发的服务器:端口
smtp_sasl_auth_enable = yes #开启sasl验证
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd #指定密码文件
smtp_tls_security_level = encrypt #postfix SMTP客户端的默认SMTP TLS安全级别
smtp_sasl_security_options = noanonymous #禁止匿名用户
配置验证密码文件
vim /etc/postfix/sasl_passwd
[smtp.163.com]:25 test@163.com:xxn15249274366
postmap hash:/etc/postfix/sasl_passwd
使用postmap在/etc/postfix/目录下生成.db密码文件
systemctl restart postfix #重启postfix服务
SMTP服务本机测试:
[root@s postfix]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 bogon ESMTP Postfix
mail from:test@163.com
250 2.1.0 Ok
rcpt to: 123456@qq.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
this is test mail postfix
.
250 2.0.0 Ok: queued as D433586D2
成功
注意要点:
- main.cnf配置文件里的smtp服务器地址要和sasl_passwd文件中保持一致。
- sasl_passwd文件中密码是邮箱的授权码,不要写成邮箱密码。
- 每次修改了sasl_passwd文件必须要使用postmap命令重新生成一次新的.db文件。
- 一定要在防火墙开放smtp的端口;默认是 25 端口。
- 在需要发邮件的服务配置里,发件人邮箱和密码一定要和sasl_passwd文件中指定的保持一致。