如何更正 Postfix 的“中继访问被拒绝”?

Noa*_*ich 63 linux smtp postfix

今天早上,为了更正安全证书中名称不匹配的问题,我遵循了如何修复邮件服务器 SSL?,但是现在,当尝试从客户端(在这种情况下客户端是 Windows Mail)发送电子邮件时,我收到以下错误。

被拒绝的电子邮件地址是“email@gmail.com”。主题'这是一个测试。',帐户:'mail.domain.com',服务器:'mail.domain.com',协议:SMTP,服务器响应:'554 5.7.1:中继访问被拒绝',端口:25,安全(SSL):否, 服务器错误:554,错误编号:0x800CCC79

编辑:我仍然可以从此帐户检索电子邮件,并且我将电子邮件发送到同一域中的其他帐户。我只是无法向我们域外的收件人发送电子邮件。

我尝试完全禁用 TLS 但没有骰子,我仍然遇到相同的错误。

当我检查 file 时mail.log,我看到以下内容。

Jul 18 08:24:41 company imapd: LOGIN, user=user_name@domain.com, ip=[::ffff:111.111.11.11], protocol=IMAP
Jul 18 08:24:42 company imapd: DISCONNECTED, user=user_name@domain.com, ip=[::ffff:111.111.11.11], headers=0, body=0, rcvd=83, sent=409, time=1
Jul 18 08:25:19 company postfix/smtpd[29282]: connect from company.university.edu[111.111.11.11]
Jul 18 08:25:19 company postfix/smtpd[29282]: NOQUEUE: reject: RCPT from company.university.edu[111.111.11.11]: 554 5.7.1 <email@gmail.com>: Relay access denied; from=<user_name@domain.com> to=<email@gmail.com> proto=ESMTP helo=<UserPC>
Jul 18 08:25:19 company postfix/smtpd[29282]: disconnect from company.university.edu[111.111.11.11]
Jul 18 08:25:22 company imapd: DISCONNECTED, user=user_name@domain.com, ip=[::ffff:111.111.11.11], headers=13, body=142579, rcvd=3289, sent=215892, time=79
Run Code Online (Sandbox Code Playgroud)

文件main.cf如下所示:

#
# Postfix MTA Manager Main Configuration File;
#
# Please do NOT edit this file manually;
#

#
# Postfix directory settings; These are critical for normal Postfix MTA functionallity;
#

command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
program_directory = /usr/lib/postfix

#
# Some common configuration parameters;
#

inet_interfaces = all
mynetworks = 127.0.0.0/8
mynetworks_style = host

myhostname = mail.domain.com
mydomain = domain.com
myorigin = $mydomain

smtpd_banner = $myhostname ESMTP 2.4.7.1 (Debian/GNU)
setgid_group = postdrop

#
# Receiving messages parameters;
#

mydestination = localhost, company 
append_dot_mydomain = no
append_at_myorigin = yes
transport_maps = mysql:/etc/postfix/transport.cf

#
# Delivering local messages parameters;
#

mail_spool_directory = /var/spool/mail
mailbox_size_limit = 0
mailbox_command = procmail -a "$EXTENSION"

biff = no

alias_database = hash:/etc/aliases

local_recipient_maps =

#
# Delivering virtual messages parameters;
#
virtual_mailbox_maps=mysql:/etc/postfix/mysql_virt.cf
virtual_uid_maps=mysql:/etc/postfix/uids.cf
virtual_gid_maps=mysql:/etc/postfix/gids.cf
virtual_mailbox_base=/usr/local/virtual
virtual_maps=mysql:/etc/postfix/virtual.cf
virtual_mailbox_domains=mysql:/etc/postfix/virtual_domains.cf


#
# SASL paramters;
#
smtp_use_tls = yes
smtpd_use_tls = yes
smtpd_tls_auth_only = yes
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s

smtp_tls_CAfile = /etc/postfix/ssl/smptd.pem
smtp_tls_cert_file = /etc/postfix/ssl/smptd.crt
smtp_tls_key_file = /etc/postfix/ssl/smptd.key

smtpd_tls_CAfile = /etc/postfix/ssl/smptd.pem
smtpd_tls_cert_file = /etc/postfix/ssl/smptd.crt
smtpd_tls_key_file = /etc/postfix/ssl/smptd.key

smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

smtpd_sasl_local_domain =

broken_sasl_auth_clients = yes

smtpd_sender_restrictions =
        permit_sasl_authenticated
        permit_mynetworks

smtpd_recipient_restrictions =
        permit_sasl_authenticated
        check_recipient_access hash:/etc/postfix/filtered_domains
        permit_mynetworks
        reject_unauth_destination
Run Code Online (Sandbox Code Playgroud)

作为旁注,我的雇主希望能够从我们的本地网络内部和外部发送来自客户(Thunderbird 和 Outlook)的电子邮件。

小智 67

TLS 仅对 smtp 会话启用加密,并不直接影响是否允许 Postfix 中继消息。

出现中继拒绝消息是因为 smtpd_recipient_restrictions 规则不匹配。必须满足这些条件之一才能允许消息通过:

smtpd_recipient_restrictions =
    permit_sasl_authenticated
    check_recipient_access hash:/etc/postfix/filtered_domains
    permit_mynetworks
    reject_unauth_destination
Run Code Online (Sandbox Code Playgroud)

解释这些规则:

permit_sasl_authenticated
Run Code Online (Sandbox Code Playgroud)

允许通过 SASL 进行身份验证的发件人。这对于验证通常被阻止的网络之外的用户是必要的。

check_recipient_access
Run Code Online (Sandbox Code Playgroud)

这将导致 postfix 根据收件人地址在 /etc/postfix/filtered_domains 中查找规则。(从文件名上的文件名来看,可能只是屏蔽了特定的域……查看gmail.com是否列在那里?)

permit_mynetworks
Run Code Online (Sandbox Code Playgroud)

这将允许按 IP 地址匹配 $mynetworks 中指定的 IP 范围的主机。在您发布的 main.cf 中,$mynetworks 设置为 127.0.0.1,因此它只会中继服务器本身生成的电子邮件。

根据该配置,您的邮件客户端在被允许中继邮件之前需要使用 SMTP 身份验证。我不确定 SASL 正在使用什么数据库。这是在 /usr/lib/sasl2/smtpd.conf 中指定的,大概它也使用与您的虚拟邮箱相同的数据库,因此您应该能够在邮件客户端中启用 SMTP 身份验证并进行所有设置。


pgs*_*pgs 16

smtpd_use_tls = no
Run Code Online (Sandbox Code Playgroud)

您已禁用 TLS,因此您现在需要通过将其添加到mynetworks. 例如,

mynetworks = 192.168.1.0/24 127.0.0.0/8
Run Code Online (Sandbox Code Playgroud)

这将仅解决从本地网络发送的问题。要从本地网络外部发送电子邮件,您需要使 TLS 身份验证正常工作。

  • 我并不是说他应该禁用 tls;我是说因为他已经禁用了它,所以他需要设置 mynetworks。完整的解决方案是让 tls 再次工作。 (3认同)

小智 8

我想你想念你在 mydestination 中的 domain.com,因为默认relay_domains=$mydestination,所以你可以附加你的配置行:

mydestinations = $mydomain, $myhostname, localhost, localhost.localdomain
Run Code Online (Sandbox Code Playgroud)

或者:

relay_domains = $mydomain
Run Code Online (Sandbox Code Playgroud)

service postfix restart每次编辑 postfix conf 文件时不要忘记重新启动 postfix 服务器 ( )。