我设置了 postifx 作为邮件中继,并配置了外部 smtp 服务器。总体来说,这很好用。但我的目标是,所有邮件都将转发到外部 smtp 服务器 - 除 root 外。
/etc/postfix/main.cf:
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = example.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = localhost
relayhost = [smtp.relay.com]:587
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 127.0.0.1
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtpd_use_tls=yes
smtp_tls_security_level = encrypt
使用此配置,postfix 尝试将 root 邮件发送到[电子邮件保护]通过 SMTP 服务器。对于 root 用户来说,本地交付是我首选的解决方案。
有人可以帮忙吗?
谢谢!
答案1
由于 Postfix 设置提供了多种设置,以下是一些注意事项可能帮助,因为他们在安装了 postfix 的 Ubuntu 16 系统上启用了本地邮件传递(不同系统上的路径可能不同):
Postfix 不会向 root 发送邮件,但您可以将所有 root 邮件重定向到另一个本地主机用户帐户,例如 postfix 用户(如果存在),但任何其他用户都可以。为此编辑
/etc/别名
例如:
postmaster: <USER1>
root: <USER1>
<USER2>: <USER1>
...
然后发出命令
sudo newaliases
必须安装 Procmail,可以通过以下命令完成
sudo apt 安装 procmail
(如果 procmail 已经安装,则可以中止。)
一些设置在
/etc/postfix/main.cf
或许
myhostname = <HOSTNAME>@<LOCALNET>
mydestination = <ALL HOSTNAMES ASSIGNED TO 127.0.0.1, MAYBE ::1, IN /etc/hosts, DELIMITED BY SPACE>
local_transport = local
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
# following all possible arguments, strip as you like
notify_classes = bounce, 2bounce, delay, policy, protocol, resource, software
修改将在发出命令后生效
sudo 服务 postfix 重启
阅读日志文件很有帮助
/var/log/mail.log,/var/log/mail.err
更多有用的阅读材料:
http://www.postfix.org/BASIC_CONFIGURATION_README.html
http://www.postfix.org/LOCAL_RECIPIENT_README.html