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服务器不允许中继到(或来自)这个地址。 有人build议我确保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] 

后缀日志说:

 > 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地址和ipaddresses。

更新:

经过几个星期试图得到这个工作,并感谢大家的帮助,我find了解决scheme。 我试图使用本地主机作为中继主机,但因为这是一个godaddy托pipe的服务器所有中继必须通过指定的中继主机。 我所需要做的就是改变SMTP的位置。 现在是:

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

您可能需要在/etc/postfix/main.cf中设置几个区域。 如果您正在使用您的Web主机的SMTP服务器作为中继,例如,您将需要寻找与“relayhost =”部分。

根据什么交付方式:直接或间接 :

默认情况下,Postfix尝试将邮件直接发送到Internet。 根据您当地的情况,这可能是不可能或不可取的。 例如,您的系统可能在办公时间以外closures,可能位于防火墙后面,或者可能通过不允许直接邮寄到Internet的提供商连接。 在这种情况下,您需要configurationPostfix通过中继主机间接传送邮件。

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

 /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) 

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

你的默认configuration应该有上面的东西。 根据您的设置select一个有效的configuration并将其他注释掉。

我也build议查看有关继电器和networkingconfiguration的其他部分,看看您的设置是否符合规格: Postfix的基本configuration