如何让 Postfix 将收到的电子邮件中继到特定主机,并将发出的邮件中继到所需的任何主机?

如何让 Postfix 将收到的电子邮件中继到特定主机,并将发出的邮件中继到所需的任何主机?

我有一个像这样的 Postfix 设置:

     __________                     +-----+     |F|        +-----+
  __(          )____               /     /|     |I|       /     /|
 (___  (         ___)             /     / |     |R|      /     / |
    _(  Internet )     <=====>   +-----+  |  <==|E|==>  +-----+  |
   (___,     )   _)              |  M  |  |     |W|     |  H  |  |
       (_________)               |  A  |  +     |A|     |  O  |  +
                                 |  I  | /      |L|     |  S  | /
                                 |  L  |/       |L|     |  T  |/
                                 +--+--+        | |     +-----+

我现在已经配置好了从mail到 的邮件转发功能。以下是的host输出:postconf -nmail

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
inet_protocols = ipv4
mailbox_size_limit = 0
message_size_limit = 41943040
mydestination =
myhostname = example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 203.0.113.190
readme_directory = no
recipient_delimiter = +
relay_domains = host.example.com, example.com, example.org,
relayhost = [host.example.com]:587
smtp_tls_CApath = /etc/ssl/certs
smtp_tls_loglevel = 1
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination,
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination,
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous, noplaintext,
smtpd_sasl_tls_security_options = noanonymous,
smtpd_sasl_type = cyrus
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5,
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3,
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
tls_preempt_cipherlist = yes

这很完美 – 我可以从 Gmail 和其他提供商发送邮件,并且它们可以正确地发送到我的邮箱中host

然而,当我尝试发送电子邮件时,host我很确定它正在尝试中继电子邮件后退mailhost。我在日志中看到以下内容host

Dec 28 16:44:28 host postfix/submission/smtpd[29743]: warning: hostname mail2.example.com does not resolve to address 203.0.113.14: Name or service not known
Dec 28 16:44:28 host postfix/submission/smtpd[29743]: connect from unknown[203.0.113.14]
Dec 28 16:44:28 host postfix/submission/smtpd[29743]: Anonymous TLS connection established from unknown[203.0.113.14]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Dec 28 16:44:28 host postfix/submission/smtpd[29743]: NOQUEUE: reject: RCPT from unknown[203.0.113.14]: 454 4.7.1 <[email protected]>: Relay access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<example.com>
Dec 28 16:44:28 host postfix/submission/smtpd[29743]: disconnect from unknown[203.0.113.14]

然后mail我得到了这些日志:

Dec 28 16:54:27 mail postfix/smtp[17899]: Untrusted TLS connection established to host.example.com[203.0.113.190]:587: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
Dec 28 16:54:28 mail postfix/smtp[17899]: 7B6A620FFB: to=<[email protected]>, relay=host.example.com[203.0.113.190]:587, delay=1064, delays=1063/0.01/0.71/0.08, dsn=4.7.1, status=deferred (host host.example.com[203.0.113.190] said: 454 4.7.1 <[email protected]>: Relay access denied (in reply to RCPT TO command))

在 上host,这是我的postconf -n输出:

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
inet_protocols = ipv4
mailbox_size_limit = 0
message_size_limit = 41943040
mydestination = host, host.example.com, example.com
myhostname = host.example.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
readme_directory = no
recipient_delimiter = +
relay_domains = $mydestination
relayhost = example.com:587
smtp_tls_CApath = /etc/ssl/certs
smtp_tls_loglevel = 1
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination,
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination,
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous, noplaintext,
smtpd_sasl_tls_security_options = noanonymous,
smtpd_sasl_type = cyrus
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_loglevel = 1
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5,
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3,
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
tls_preempt_cipherlist = yes
postconf: warning: /etc/postfix/main.cf: unused parameter: compatibility_level=2

基本上我想要的是:

开启hostmail

我该如何配置 postfix 才能正确执行此操作?

答案1

事实证明这比我想象的要容易得多。在以下文档中找到了线索:中继传输

按优先级降序排列,下一跳目的地取自 $relay_transport、$sender_dependent_relayhost_maps,$relayhost,或者来自收件人域。此信息可被运输(5)桌子

(重点是我的)

我想反过来想——我希望收件人域名排在第一位,然后中继主机。由于文档说我可以查看 transport(5) 表,所以我就这么做了。我发现了以下信息:

local_transport (default: local:$myhostname)
          This is the default for final delivery to  domains  listed  with
          mydestination,  and  for  [ipaddress]  destinations  that  match
          $inet_interfaces or $proxy_interfaces. The default nexthop  des-
          tination is the MTA hostname.

这看起来很有希望。如果我理解正确的话,这意味着我可以使用smtp:host.example.com:587as mylocal_transport并使用mydestination代替relay_domains。猜猜怎么着?它成功了!

因此,不要:

mydestination =
relay_domains = host.example.com, example.com, example.org,
relayhost = [host.example.com]:587

我刚刚

mydestination = host.example.com, example.com, example.org,
local_transport = smtp:[host.example.com]:587

并且它完全按照预期运行,成功!

相关内容