为什么当我尝试向外部域发送电子邮件时,我的 postfix 返回“中继访问被拒绝”?

为什么当我尝试向外部域发送电子邮件时,我的 postfix 返回“中继访问被拒绝”?

这是一个相当常见的问题,但我找到的任何答案(例如如何纠正 Postfix 的“中继访问被拒绝”?https://unix.stackexchange.com/questions/360960/relay-access-deniedhttps://stackoverflow.com/questions/18318789/linux-postfix-dovecot-554-relay-access-denied) 不起作用。我已经花了好几天时间试图找出错误根源,但毫无进展。

当我使用我的邮件客户端向外部域发送电子邮件时,日志(/var/log/mail.log)显示以下内容:

2 月 24 日 19:02:37(姓名)postfix/submission/smtpd[27783]: 连接自(我的域名)[(我的 IP)]

2 月 24 日 19:02:37(姓名)postfix/submission/smtpd[27783]: NOQUEUE: 拒绝: RCPT 来自(我的域名)[(我的 IP)]:554 5.7.1 <(我的电子邮件)@gmail.com>:中继访问被拒绝;来自=<admin@(我的域名)> 至=<(我的电子邮件)@gmail.com> proto=ESMTP helo=<邮件。(我的域名)>

2 月 24 日 19:02:37(姓名)postfix/submission/smtpd[27783]: 断开与(我的域名)[(我的 IP)] ehlo=2 starttls=1 auth=1 mail=1 rcpt=0/1 rset=1 quit=1 命令=7/8

这里的一切都符合我的预期。请求来自我自己的域,使用我自己的 IP。我的域配置为 virtual_host,我的 IP 地址在 /etc/postfix/main.cf 中的键下指定mynetworks。此外,我已按照其他地方的建议设置smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination。这些都无助于缓解此错误。

编辑:添加了输出postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
compatibility_level = 2
inet_interfaces = all
inet_protocols = all
mailbox_size_limit = 0
milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
mydestination = localhost.(my tld), , localhost, (my ip), 127.0.0.1
myhostname = (my domain)
mynetworks = 127.0.0.0/8, [::ffff:127.0.0.0]/104, [::1]/128, 127.0.0.1, (my ip)
myorigin = /etc/mailname
non_smtpd_milters = inet:127.0.0.1:11332
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_milters = inet:127.0.0.1:11332
smtpd_recipient_restrictions = reject_unauth_destination check_policy_service unix:private/quota-status
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_sender_login_maps = mysql:/etc/postfix/mysql-email2email.cf
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = (path to certs)/fullchain.pem
smtpd_tls_key_file = (path to certs)/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp

编辑:这是/etc/postconf/master.cf

submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_tls_auth_only=yes
  -o smtpd_reject_unlisted_recipient=no
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING

pickup    unix  n       -       y       60      1       pickup
cleanup   unix  n       -       y       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       y       1000?   1       tlsmgr
rewrite   unix  -       -       y       -       -       trivial-rewrite
bounce    unix  -       -       y       -       0       bounce
defer     unix  -       -       y       -       0       bounce
trace     unix  -       -       y       -       0       bounce
verify    unix  -       -       y       -       1       verify
flush     unix  n       -       y       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       y       -       -       smtp
relay     unix  -       -       y       -       -       smtp
        -o syslog_name=postfix/$service_name
showq     unix  n       -       y       -       -       showq
error     unix  -       -       y       -       -       error
retry     unix  -       -       y       -       -       error
discard   unix  -       -       y       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       y       -       -       lmtp
anvil     unix  -       -       y       -       1       anvil
scache    unix  -       -       y       -       1       scache

maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}

uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)

ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

导致错误的原因是什么Relay access denied

答案1

smtpd_relay_restrictions控制谁可以通过您的 Postfix 服务器进行中继。

通过按如下所示进行设置(注意逗号),您应该没问题:

smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

当然你还应该配置我的网络参数包含您想要连接和发送邮件的 IP 地址。例如:

mynetworks = 127.0.0.0/8, 192.168.0.0/24

另外,请确保您没有设置任何其他 smtpd_*_restrictions,或者如果需要,请进行类似于以下的配置smtpd_relay_restrictions. 运行 postconf -n:

postconf -n | grep restrictions

相关内容