让Postfix转发所有本地邮件到服务器

不知道为什么要这么做,姑且做个备忘。

可选步骤:使用外部SMTP服务器

建立文件/etc/postfix/sasl_passwd ,内容为

[smtp.server.domain]:port username:password

建立对应的Hash DB

postmap /etc/postfix/sasl_passwd

控制访问权限(里面有明文密码)

chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

打开配置文件/etc/postfix/main.cf ,新建/更改行

# SMTP server
relayhost = [smtp.server.domain]:port
# enable SASL authentication 
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication. 
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption 
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

配置本地邮件转发

设立转发配置文件/etc/postfix/virtual ,内容:

# Single receiver, more than 1 forwarding destination
[email protected] [email protected] [email protected]
# Wildcard username
@example.org [email protected]

同样建立Hash DB:

postmap /etc/postfix/virtual

修改配置文件:

# forwarding server
virtual_alias_domains = localhost_hostname
virtual_alias_maps = hash:/etc/postfix/virtual

# Enable TLS
smtp_use_tls=yes
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

重启一下服务

systemctl restart postfix.service

参考资料

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据