Chinaunix

标题: postfix不能向外发邮件?? [打印本页]

作者: 13319085    时间: 2008-11-27 21:53
标题: postfix不能向外发邮件??
我想请教一个问题:我的环境是这样的,linuxOS5.2本机搭有postfix,运行postfix check 无错 ,dovecotf服务已启动,在外网注册了域名,外网DNS并指了MX 记录,指到了本服务器,端口25已开放,能收到邮件,可是还是不能想外网发送邮件,日志没有错误,我实在是不知道在哪出了问题,希望哪位兄弟能帮的指点一下思路!先谢了
作者: xiaoyun5109    时间: 2008-11-27 21:53
默认情况下,Postfix邮件主机可以接受和转发符合以下条件的邮件:
                (1)接受邮件
                        目的地为$inet_interfaces的邮件;
                        目的地为$mydestination的邮件;
                        目的地为$vitual_alias_maps的邮件。
                (2)转发邮件
                        来自客户端IP地址符合$mynetworks的邮件;
                        来自客户端主机名称符合$relay_domains及其子域的邮件
                        目的地为$relay_domains及其子域的邮件

从以上可以知道,要能转发邮件出去,关键是mynetworks和relay_domains两个设置项目。
mynetworkds主要设置需要转发的网段
relay_domains设置能转发的域

所以要把内网的邮件转发出去,可以设置:
mynetworks = 10.10.0.0/16, 127.0.0.1/8
relay_domains = abc.com

注:内网地址段为10.10.0.0/16,本单位域名为abc.com
作者: jerrywjl    时间: 2008-11-28 00:03
需要提供配置和日志。
作者: 13319085    时间: 2008-11-28 01:04
谢谢楼上的提示,以下是进一步的说明


配置就是更改了main.cf文件下的主机名、域名、显示名,接收的域名,监听端口是all,network_styp=class  日志没有异常,只是显示一些邮件的基本内容,用telnet **.***.** 25 后


[root@mail log]# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.****com ESMTP Postfix
之后就没反应了,我也不太清楚啊

[ 本帖最后由 13319085 于 2008-11-28 01:06 编辑 ]
作者: kns1024wh    时间: 2008-11-28 09:02
标题: 回复 #1 13319085 的帖子
1、调整你的mynetworks = 127.0.0.1这个参数,增加能够发送电子邮件的网络或者是主机地址但是会产生relay的问题;
2、你现在的配置里面没有使用CyrusSASL进行身份认证,
检测是否安装
# rpm -qa|grep cyrus  
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-lib-2.1.22-4
cyrus-sasl-2.1.22-4
/etc/postfix/main.cf的配置文件
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain= ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,
           reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
作者: cuci    时间: 2008-11-28 09:03
你telnet结果很正常阿,继续往下作阿
作者: 13319085    时间: 2008-11-28 12:06
标题: 回复 #5 cuci 的帖子
往下做了,可还是不行,查看smtp协议时没有发现数据包
作者: cuci    时间: 2008-11-28 12:22
往下作啥了,要看看提示什么,log记录什么
作者: jerrywjl    时间: 2008-11-28 12:24
根据下面的这个例子,好好看看这几个地方是否都有修改:
postfix的主要配置文件是main.cf
修改main.cf

inet_interfaces = localhost
改成
inet_interfaces = all

#myhostname = host.domain.tld
改成
myhostname = mail.apple.com

#mydomain = domain.tld
改成
mydomain = apple.com

mydestination = $myhostname, localhost.$mydomain, localhost
改成
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
作者: 13319085    时间: 2008-11-28 13:41
标题: 回复 #8 jerrywjl 的帖子
谢谢你的答复,这些之前都改过了
作者: jerrywjl    时间: 2008-11-28 13:42
那就见了鬼了,跑一个sosreport,把收到的结果贴上来看看。
作者: 13319085    时间: 2008-11-28 13:54
标题: 回复 #7 cuci 的帖子
[root@mail ~]# telnet mail.***.com 25
Trying 59.*.*1**...
Connected to mail.***.com (59.*.*.1**).
Escape character is '^]'.
220 mail.****.com ESMTP Postfix
helo mail.sina.com
250 mail.***.com
mail from:<zhang***@sina.com>
250 Ok
rcpt to:<root@***.com>
250 Ok
data
354 End data with <CR><LF>.<CR><LF>




no.......
这是你要的测试,后面就没反应了!需兄弟进一步提示!!!
作者: cuci    时间: 2008-11-28 14:01
原帖由 13319085 于 2008-11-28 13:54 发表
[root@mail ~]# telnet mail.***.com 25
Trying 59.*.*1**...
Connected to mail.***.com (59.*.*.1**).
Escape character is '^]'.
220 mail.****.com ESMTP Postfix
helo mail.sina.com
250 mail.***.c ...



这不很正常吗,继续阿
作者: 13319085    时间: 2008-11-28 14:02
标题: 回复 #7 cuci 的帖子
Nov 28 12:23:51 localhost postfix/smtpd[6380]: disconnect from unknown[121.37.23
.202]
Nov 28 12:27:11 localhost postfix/anvil[6382]: statistics: max connection rate 1
/60s for (smtp:121.37.23.202) at Nov 28 12:23:51
Nov 28 12:27:11 localhost postfix/anvil[6382]: statistics: max connection count
1 for (smtp:121.37.23.202) at Nov 28 12:23:51
Nov 28 12:27:11 localhost postfix/anvil[6382]: statistics: max cache size 1 at N
ov 28 12:23:51
Nov 28 12:40:12 localhost postfix/smtpd[6411]: warning: 58.61.74.107: hostname 1
07.74.61.58.broad.sz.gd.dynamic.163data.com.cn verification failed: Name or serv
ice not known
Nov 28 12:40:12 localhost postfix/smtpd[6411]: connect from unknown[58.61.74.107
]
Nov 28 12:40:12 localhost postfix/smtpd[6411]: NOQUEUE: reject: RCPT from unknow
n[58.61.74.107]: 554 <xxxxxx@sip.i2m.cn>: Relay access denied; from=<79999...wsr
t@you.com> to=<xxxxxx@sip.i2m.cn> proto=ESMTP helo=<you.com>
收到一些其他的邮件,日志没有错误!!
########################################################
Nov 28 13:59:33 localhost postfix/master[6607]: daemon started -- version 2.2.10
, configuration /etc/postfix
Nov 28 13:59:39 localhost postfix/postfix-script: refreshing the Postfix mail sy
stem
Nov 28 13:59:39 localhost postfix/master[6607]: reload configuration /etc/postfi
x
Nov 28 14:03:29 localhost postfix/postfix-script: refreshing the Postfix mail sy
stem
Nov 28 14:03:29 localhost postfix/master[6607]: reload configuration /etc/postfi
x
Nov 28 14:03:36 localhost postfix/postfix-script: stopping the Postfix mail syst
em
Nov 28 14:03:36 localhost postfix/master[6607]: terminating on signal 15
Nov 28 14:03:42 localhost postfix/postfix-script: starting the Postfix mail syst
em
Nov 28 14:03:42 localhost postfix/master[6709]: daemon started -- version 2.2.10
, configuration /etc/postfix
Nov 28 14:03:47 localhost postfix/postfix-script: refreshing the Postfix mail sy
stem
Nov 28 14:03:47 localhost postfix/master[6709]: reload configuration /etc/postfi
x
Waiting for data... (interrupt to abort)
重启后一段时间的日志
日志,小弟不是很懂,帮忙指点一下

[ 本帖最后由 13319085 于 2008-11-28 14:11 编辑 ]
作者: 13319085    时间: 2008-11-28 14:41
标题: 回复 #12 cuci 的帖子
怎么继续呀??像这样


date: mon,8 apr 2003 15:38:21 -0500
from: Customer Service <zhangxxx@sina.com>
to: <root@xxx.com>
reply-TO: <service@sina.com>            
message-ID: <01A4E2238200842@mail.sina.com>
subject: ddd   

this is the start of the body of the message. it could continue for many lines,but it doesn't.


###########3
这样也是没有反应

[ 本帖最后由 13319085 于 2008-12-1 11:07 编辑 ]
作者: 13319085    时间: 2008-11-28 16:38
标题: 回复 #4 kns1024wh 的帖子
身份认证加这些就可以用了吗??还有转发会遇到什么样的问题?
作者: 13319085    时间: 2008-11-28 17:26
main.cf

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
mail_owner = postfix
myhostname = mail.haha.com
mydomain = haha.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks_style = class
作者: cuci    时间: 2008-11-28 17:41
Nov 28 12:40:12 localhost postfix/smtpd[6411]: NOQUEUE: reject: RCPT from unknow
n[58.61.74.107]: 554 <xxxxxx@sip.i2m.cn>: Relay access denied; from=<79999...wsr
t@you.com> to=<xxxxxx@sip.i2m.cn> proto=ESMTP helo=<you.com>

禁止relay
data之后直接写些信头信息或者内容,最后。结束,就ok
作者: 13319085    时间: 2008-11-28 21:16
标题: 回复 #17 cuci 的帖子
十分感谢楼上的关注和帮助,我去试试!!
作者: 13319085    时间: 2008-11-29 16:42
还是不行啊,怎么禁relay??是这个吗??
smtpd_sasl_auth_enable = no
broken_sasl_auth_clients = no
作者: 13319085    时间: 2008-11-29 22:43
标题: 回复 #12 cuci 的帖子
下面是测试::
[root@mail postfix]# telnet mail.####.com 25
Trying 59.###...
Connected to mail.####b.com (59.###).
Escape character is '^]'.
220 mail.####com ESMTP Postfix
helo mail.sina.com
250 mail.####.com
mail from:<zhang###@sina.com>
250 2.1.0 Ok
rcpt to:<root@###.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
uuu
.
250 2.0.0 Ok: queued as 14B551BC400E
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have new mail in /var/spool/mail/root
下面是测试结果::
Nov 29 22:25:21 localhost postfix/master[16545]: daemon started -- version 2.5.5, configuration /etc/postfix/
Nov 29 22:31:05 localhost dovecot: Dovecot starting up
Nov 29 22:32:40 localhost postfix/smtpd[16589]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Nov 29 22:32:45 localhost postfix/smtpd[16589]: connect from unknown[59.####]
Nov 29 22:34:38 localhost postfix/smtpd[16589]: 14B551BC400E: client=unknown[59.####]
Nov 29 22:39:37 localhost postfix/cleanup[16653]: 14B551BC400E: message-id=<20081129143438.14B551BC400E@mail.####.com>
Nov 29 22:39:37 localhost postfix/qmgr[16546]: 14B551BC400E: from=<zhang###@sina.com>, size=339, nrcpt=1 (queue active)
Nov 29 22:39:37 localhost postfix/local[16758]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Nov 29 22:39:37 localhost postfix/local[16758]: 14B551BC400E: to=<root@####.com>, relay=local, delay=339, delays=339/0.01/0/0, dsn=2.0.0, stat
us=sent (delivered to mailbox)
Nov 29 22:39:37 localhost postfix/qmgr[16546]: 14B551BC400E: removed
Nov 29 22:40:13 localhost postfix/smtpd[16589]: disconnect from unknown[59.####]

谁来帮的分析一下啊,我不胜感激!!

[ 本帖最后由 13319085 于 2008-11-29 23:33 编辑 ]
作者: 13319085    时间: 2008-11-29 23:30
下面是测试发信的过程:
[root@mail ~]# telnet mail.@@@.com 25
Trying 59.####...
Connected to mail.@@@(59.@@@).
Escape character is '^]'.
220 mail.###.com ESMTP Postfix
helo mail.@@@
250 mail.@@@
mail from:<root@@@@.com>
250 2.1.0 Ok
rcpt to:<zhang@@@@gmail.com>
554 5.7.1 <zhang@@@@gmail.com>: Relay access denied
rcpt to:<zhang@@@sina.com>
554 5.7.1 <zhang@@@sina.com>: Relay access denied
发信过程中的日志::
Nov 29 23:06:42 localhost postfix/postfix-script[16909]: stopping the Postfix mail system
Nov 29 23:06:42 localhost postfix/master[16545]: terminating on signal 15
Nov 29 23:07:14 localhost postfix/postfix-script[16958]: starting the Postfix mail system
Nov 29 23:07:14 localhost postfix/master[16959]: daemon started -- version 2.5.5, configuration /etc/postfix/
Nov 29 23:07:54 localhost postfix/smtpd[16964]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Nov 29 23:07:54 localhost postfix/smtpd[16964]: connect from unknown[59.@@@]    \\这里为什么是未知的??
Nov 29 23:09:46 localhost postfix/smtpd[16964]: NOQUEUE: reject: RCPT from unknown[59.@@@]: 554 5.7.1 <zhangb###@gmail.com>: Relay access
denied; from=<root@hamob.com> to=<zhang##@gmail.com> proto=SMTP helo=<mail.@@@.com>
Nov 29 23:10:45 localhost postfix/smtpd[16964]: NOQUEUE: reject: RCPT from unknown[59@@@]: 554 5.7.1 <zhang@@@sina.com>: Relay access \\这里也有
denied; from=<root@###.com> to=<zhang##@sina.com> proto=SMTP helo=<mail.@@@.com>
Waiting for data... (interrupt to abort)
我的MX记录测试了,下面是测试结果:

C:\Documents and Settings\ufo>nslookup
*** Can't find server name for address 61.232.10.59: Non
Default Server:  gjjline.bta.net.cn
Address:  202.106.0.20

> set q=MX
>
> ####.com
Server:  gjjline.bta.net.cn
Address:  202.106.0.20

Non-authoritative answer:
###.com       MX preference = 1, mail exchanger = mail。###。com

com     nameserver = c.gtld-servers.net
com     nameserver = h.gtld-servers.net
com     nameserver = j.gtld-servers.net
com     nameserver = d.gtld-servers.net
com     nameserver = a.gtld-servers.net
com     nameserver = f.gtld-servers.net
com     nameserver = i.gtld-servers.net
com     nameserver = g.gtld-servers.net
com     nameserver = b.gtld-servers.net
com     nameserver = m.gtld-servers.net
com     nameserver = l.gtld-servers.net
com     nameserver = e.gtld-servers.net
com     nameserver = k.gtld-servers.net
c.gtld-servers.net      internet address = 192.26.92.30
j.gtld-servers.net      internet address = 192.48.79.30
i.gtld-servers.net      internet address = 192.43.172.30
l.gtld-servers.net      internet address = 192.41.162.30

[ 本帖最后由 13319085 于 2008-11-29 23:34 编辑 ]
作者: ynchnluiti    时间: 2008-11-30 11:36
20楼是发送成功了
mail from:<zhang###@sina.com>
250 2.1.0 Ok
rcpt to:<root@###.com>

21楼给gmail发送失败。启用认证试试。主要是下面几个选项的设置
  1. smtpd_sasl_auth_enable
  2. smtpd_sasl_security_options
  3. broken_sasl_auth_clients
  4. smtpd_recipient_restrictions
  5. smtpd_client_restrictions
复制代码

作者: 13319085    时间: 2008-11-30 12:02
标题: 回复 #22 ynchnluiti 的帖子
楼上能具体点吗??
作者: ynchnluiti    时间: 2008-11-30 18:17
原帖由 13319085 于 2008-11-30 12:02 发表
楼上能具体点吗??
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients=yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous


telnet发送邮件前也要认证:
如果服务器smtp需要验证,helo完要输入
AUTH LOGIN
提示
334 VXNlcm5hbWU6 即 Username:
和 334 UGFzc3dvcmQ6 即 Password:
后边的内容是提示输入用户名和口令,信息是经过base64编码的
输入的用户名和口令也要经过编码。
smtp认证通过后会显示
235 2.0.0 Authentication successful


另外,relay控制。主要是设置
inet_interfaces
mynetworks_style
mynetworks
relay_domains
作者: 13319085    时间: 2008-12-01 11:05
标题: 回复 #24 ynchnluiti 的帖子
多谢楼上的答复,我现在就想允许本地注册的用户通过本 MTU 向外 relay 邮件,是怎么设置的,那个sasl是用在多 MTU 的环境?小弟刚接触邮件服务器,以上是我的一些理解,是否正确期待你的答复.如果是基本的 relay 是怎么进行设置的??现在可以收邮件,但往外发邮件都是 relay 被拒绝的。
作者: songpure520    时间: 2008-12-01 11:38
因为要转发给外域的邮件,有两个方法,一个是在mynetworks指定可以发信到外域的客户端,另外的就是在relay_domains指定域名,那么这个参数就是任何客户端都可以发送到relay_domains指定的域名当中
作者: 13319085    时间: 2008-12-01 11:45
标题: 回复 #26 songpure520 的帖子
多谢楼上的答复,是不是要往外域发邮件就必须把它的域名加到relay_domains中??如果是这样的话,就必须设置sasl了!
作者: shitoryu    时间: 2008-12-01 23:46
邮件不能发出去,一般maillog中肯定有记录的,vi /etc/postfix/master.cf,变成这样
smtp  inet -  n - -  smtpd -v(多加个v).在看看日志。
先本地测试一下也可以的,echo "hello" |maildrop -V 9 -d test@test.com.
可以去这里看看这篇文章:
http://www.extmail.org/docs/extmail_solution_linux/
作者: ynchnluiti    时间: 2008-12-02 01:52
原帖由 13319085 于 2008-12-1 11:45 发表
多谢楼上的答复,是不是要往外域发邮件就必须把它的域名加到relay_domains中??如果是这样的话,就必须设置sasl了!

我这没环境,只能测试本地(同一局域网)给外域发邮件,可以成功。

楼主先试试下列方法(逐个测试,修改main.cf后别忘了重启postfix).,看看能不能成功发送邮件,熟悉一下postfix, 然后再安装sasl:
1 设置 mynetworks。示例:
mynetworks = 192.168.0.0/24, 192.168.1.0/24, 127.0.0.0/8
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table


2 添加gmail.com到mydestination
mydestination = gmail.com, ..
参考:
http://www.linuxquestions.org/qu ... tgoing-mail-649306/
http://rackerhacker.com/2007/08/ ... elay-access-denied/

3 添加gmail.com到relay_domains,不启用sasl认证。
relay_domains = gmail.com, $mydestination

Postfix sasl的安装配置在不同系统上有些出入,楼主可以根据自己的系统在网上找找。
(如果debian等系统,使用aptitude类似工具安装很方便)
作者: 13319085    时间: 2008-12-02 15:06
多谢xiaoyun5109  和 ynchnluiti 的关注和答复,
我先声明一下我的需求
由于公司要求在外地或家里的机子也能通过该 MTU 向外发送邮件,所以不能光使用mynetworkds的方法,只能开启认证,现在本地的MTU能用手动的方法正常发送和收取邮件,客户端使用outlook只能收邮件,发不了邮件,根据报错的编号是被拒绝了,postfix的日志显示如下
Dec  2 13:56:00 localhost postfix/smtpd[14209]: disconnect from unknown[219.142.226.84]
Dec  2 13:56:02 localhost postfix/smtpd[14209]: connect from unknown[219.142.226.84]
Dec  2 13:56:02 localhost postfix/smtpd[14209]: lost connection after EHLO from unknown[219.142.226.84]
Dec  2 13:56:02 localhost postfix/smtpd[14209]: disconnect from unknown[219.142.226.84]
Dec  2 13:56:02 localhost pop3-login: Login: zhangXX [219.142.226.84]
Dec  2 13:56:18 localhost pop3-login: Aborted login [219.142.226.84]
Dec  2 13:56:18 localhost postfix/smtpd[14209]: connect from unknown[219.142.226.84]
Dec  2 13:56:18 localhost postfix/smtpd[14209]: lost connection after EHLO from unknown[219.142.226.84]
Dec  2 13:56:18 localhost postfix/smtpd[14209]: disconnect from unknown[219.142.226.84]
Dec  2 13:59:38 localhost postfix/anvil[14211]: statistics: max connection rate 5/60s for (smtp:219.142.2
26.84) at Dec  2 13:55:44
Dec  2 13:59:38 localhost postfix/anvil[14211]: statistics: max connection count 1 for (smtp:219.142.226.
84) at Dec  2 13:54:44
Dec  2 13:59:38 localhost postfix/anvil[14211]: statistics: max cache size 1 at Dec  2 13:54:44
Dec  2 14:44:52 localhost postfix/smtpd[14298]: warning: dict_nis_init: NIS domain name not set - NIS loo
kups disabled
Dec  2 14:44:52 localhost postfix/smtpd[14298]: warning: smtpd_sasl_auth_enable is true, but SASL support
is not compiled in


当然我还需要看一些资料,对以上两位发来的网址深表感谢!

哪位兄弟有任何意见都可以提出来,我在此期待!

[ 本帖最后由 13319085 于 2008-12-2 15:44 编辑 ]
作者: 鬼才小科    时间: 2008-12-04 14:39
强烈建议楼主用抓包软件来分析,这样最权威!
自己动手,丰衣足食!
作者: 我爱钓鱼    时间: 2008-12-05 10:55
我比较奇怪这条日志:Dec  2 14:44:52 localhost postfix/smtpd[14298]: warning: dict_nis_init: NIS domain name not set - NIS loo
kups disabled

能不能贴出你完整的配置文件?
/etc/postfix/main.cf
/etc/postfix/master.cf
/etc/hosts
/etc/sysconfig/network的文件内容?
作者: webdna    时间: 2008-12-06 13:01
/var/log/maillog.log
看一下就知道了。或者清掉这个文件保存一下,再发邮件再看日志。
作者: 13319085    时间: 2008-12-09 10:17
谢谢各位的关注和帮助,邮件服务器已经能运行了,是认证的问题,我采用的简单的pam认证,现在在考虑搭建webmail和后台管理工具,这个比我想象的困难,我的环境改成debin3.1里面的配置和centos有不少区别,还得研究一下!


在此感谢本论坛那些热心的朋友对我的帮助,由于积分只能给一个人(其实我很想都分给大家),帮助是点点滴滴的。。。

[ 本帖最后由 13319085 于 2008-12-9 10:27 编辑 ]
作者: sky-鹏    时间: 2008-12-31 10:45
学习了,~谢谢~




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2