PostFix 中继访问被拒绝 - 原因不明显

PostFix 中继访问被拒绝 - 原因不明显

我读过很多地方有人试图解决这个问题,但没有一个对我有用。我有以下脚本

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart('alternative')
msg['Subject'] = "[Test Email]"
msg['From'] = "[email protected]"
msg['To'] = "[email protected]"

text = "sample Email"
html = "<html><body>sampleEmail</body></html>"
textPart = MIMEText(text, 'plain')
htmlPart = MIMEText(html, 'html')
msg.attach(textPart)
msg.attach(htmlPart)

s = smtplib.SMTP("localhost")
s.set_debuglevel(1)
s.sendmail("[email protected]","[email protected]", msg.as_string())
s.quit()

当我在服务器 a(称为 domain.com)上运行脚本时,一切都按预期运行。当我在服务器 b(称为 domain.biz)上运行脚本时,我收到“中继访问被拒绝”的提示。在服务器 b 上,我尝试为 domain.biz 设置自己的 postfix 实例(但并未完全成功),我可能因此而搞砸了。

我读到的所有内容都表明本地 SMTP 服务器不允许中继到(或从?)此地址。有人建议我确保smtpd_recipient_restrictions包括permit_mynetworks

sudo postconf smtpd_recipient_restrictions

打印结果为:

smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

看起来不错(问题可能是reject_unauth_destination?)。

然后他们说要确保 IP 地址包含在 mynetworks 中,所以:

sudo postconf mynetworks

打印结果为:

mynetworks = 10.0.0.0/16, 192.168.1.0/24, 127.0.0.0/8, 55.55.55.0/24, .domain.com, .domain.biz, .ip-55-55-55-55.ip.secureserver.net

正如您所看到的,我添加了我能想到的每个域名。(注意 55.55.55.55 不是真正的 IP)。

错误信息显示:

python2.7 emailTest.py
send: 'ehlo localhost.localdomain\r\n'
reply: '250-domain.biz\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 10240000\r\n'
reply: '250-VRFY\r\n'
reply: '250-ETRN\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: domain.biz
PIPELINING
SIZE 10240000
VRFY
ETRN
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'mail FROM:<[email protected]> size=565\r\n'
reply: '250 2.1.0 Ok\r\n'
reply: retcode (250); Msg: 2.1.0 Ok
send: 'rcpt TO:<[email protected]>\r\n'
reply: '554 5.7.1 <[email protected]>: Relay access denied\r\n'
reply: retcode (554); Msg: 5.7.1 <[email protected]>: Relay access denied
send: 'rset\r\n'
reply: '250 2.0.0 Ok\r\n'
reply: retcode (250); Msg: 2.0.0 Ok
Traceback (most recent call last):
  File "emailTest.py", line 122, in <module>
    s.sendmail("[email protected]","[email protected]", msg.as_string())
  File "/usr/local/lib/python2.7/smtplib.py", line 734, in sendmail
    raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'[email protected]': (554, '5.7.1 <[email protected]>: Relay access denied')}

附加 main.cf 信息:

> sudo postconf mydestination
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
> sudo postconf relay_domains
relay_domains = $mydestination
> sudo postconf mynetworks_style
mynetworks_style = subnet
> sudo postconf relayhost
relayhost = 
>sudo postconf mydomain
mydomain = domain.biz

我也尝试过:

sudo postconf relayhost
relayhost = [mail.$mydomain]

Postfix 日志显示:

> sudo tail -10 /var/log/maillog
...
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: connect from localhost[::1]
Jan 21 12:26:36 ip-50-62-42-49 postfix/trivial-rewrite[3877]: warning: do not list domain domain.biz in BOTH mydestination and virtual_alias_domains
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: NOQUEUE: reject: RCPT from localhost[::1]: 554 5.7.1 <[email protected]>: Relay access denied; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<localhost.localdomain>
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: lost connection after RSET from localhost[::1]
Jan 21 12:26:36 ip-50-62-42-49 postfix/smtpd[3875]: disconnect from localhost[::1]

sudo postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 1
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
masquerade_domains = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
mydomain = domain.biz
myhostname = domain.biz
mynetworks = 10.0.0.0/16, 192.168.1.0/24, 127.0.0.0/8, 55.55.55.0/24, .domain.com, .domain.biz, .ip-55-55-55-55.ip.secureserver.net
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relayhost = [mail.$mydomain]
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
unknown_local_recipient_reject_code = 550
virtual_alias_domains = domain.biz
virtual_alias_maps = hash:/etc/postfix/virtual

我更改了 IP 地址和 ipaddress。

更新:

经过数周的努力,在大家的帮助下,我找到了解决方案。我试图使用 localhost 作为中继主机,但因为这是 godaddy 托管的服务器,所以所有中继都必须通过指定的中继主机。我所需要做的就是更改 SMTP 的位置。现在的行是:

s = smtplib.SMTP("dedrelay.secureserver.net")

答案1

您(可能)需要在 /etc/postfix/main.cf 中设置几个区域。例如,如果您使用 Web 主机的 smtp 服务器作为中继,则需要查找带有“relayhost =”的部分。

根据交付方式:直接还是间接

默认情况下,Postfix 会尝试直接将邮件投递到 Internet。根据您当地的条件,这可能是不可能的或不理想的。例如,您的系统可能在办公时间以外关闭,可能位于防火墙后面,或者可能通过不允许将邮件直接发送到 Internet 的提供商进行连接。在这些情况下,您需要将 Postfix 配置为通过中继主机间接投递邮件。

示例(仅指定下列之一):

/etc/postfix/main.cf:

relayhost =                   (default: direct delivery to Internet)
relayhost = $mydomain         (deliver via local mailhub)
relayhost = [mail.$mydomain]  (deliver via local mailhub)
relayhost = [mail.isp.tld]    (deliver via provider mailhub)

用 [ ] 括起来的形式可消除 DNS MX 查找。如果您不知道这是什么意思,请不要担心。只需确保在您的 ISP 提供给您的 mailhub 主机名周围指定 [ ],否则邮件可能会被错误递送。

您的默认配置应该与上述类似。根据您的设置选择一个有效的配置并注释掉其他配置。

我还建议查看有关中继和网络配置的其他部分,以查看您的设置是否符合规格:Postfix 基本配置

相关内容