postfix 邮箱设置及常见错误

postfix 邮箱设置及常见错误

1、如果装了sendmail的话,先卸载了。

yum remove sendmail

2、安装 Postfix

yum install postfix

3、更改默认MTA为Postfix:

/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix

4、完事儿,再次检查下是否将MTA改为Postfix了:

alternatives --display mta

5、配置Postfix,vi编辑main.cf

vi /etc/postfix/main.cf

打开后分别找到以下几项,将其前面的#去掉,并做配置:

    myhostname = mail.wpdaxue.com
    mydomain = wpdaxue.com
    myorigin = $mydomain
    inet_interfaces = all
    inet_protocols = ipv4
    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    mynetworks = 192.168.100.10/28, 127.0.0.0/8
    relay_domains =
    home_mailbox = Maildir/

以上几个设置项不在同一个位置,需要分别寻找,并进行更改,其中相应的域名请改为自己的地址,mynetworks我是没有做改变,自动就有的。我刚开始也是配置错了导致安装失败,后来在 @朱茂海的博客找到该答案,以上几项的含义解释也来自该网站,感谢作者提供。

配置文件解释:
mydomain:
mydomain参数是指email服务器的域名,请确保为正式域名(如centos.bz)
myhostname:
myhostname参数是指系统的主机名称(如我的服务器主机名称是mail.centos.bz)
myorigin:
myorigin参数指定本地发送邮件中来源和传递显示的域名。在我们的例子中,mydomain是centos.bz,也是我的域名。
对于下面的一行,我们的邮件地址是[email protected]而不是[email protected]
myorigin = $mydomain
mynetworks:
mynetworks参数指定受信任SMTP的列表,具体的说,受信任的SMTP客户端允许通过Postfix传递邮件。
mydestination:
mydestination参数指定哪些邮件地址允许在本地发送邮件。这是一组被信任的允许通过服务器发送或传递邮件的IP地址。用户试图通过发送从此处未列出的IP地址的原始服务器的邮件将被拒绝。
inet_interfaces:
inet_interfaces参数设置网络接口以便Postfix能接收到邮件。
relay_domains:
该参数是系统传递邮件的目的域名列表。如果留空,我们保证了我们的邮件服务器不对不信任的网络开放。
home_mailbox:
该参数设置邮箱路径与用户目录有关,也可以指定要使用的邮箱风格。

6、检测并启动Postfix

service postfix status //检测,若已启动会列出其PID,如下:
master (pid 25579) is running...

//若未启动,执行以下命令:
service postfix start

7、设置开机启动

chkconfig postfix on

我自己的安装到此为止就结束了,因为我只需要的是mail功能,并非搭建邮件服务器。此时测试邮件发送,OK。

参考资料:http://www.gongzi.org/centos-install-postfix-sendmail.html

8、补充:如果你之前没有配置过 sendmail 组件,那你很可能没有修改 php.ini 的邮件发送路径,那样可能无法发送邮件。

所以你需要配置php.ini,填写sendmail的绝对路径:

使用命令打开编辑php.ini

vi /usr/local/php/etc/php.ini

输入?sendmail_path 查找定位(或者手动跳转找到sendmail_path),你会发现默认是下面的代码

;sendmail_path =

按 i 进入编辑,将这行修改为

sendmail_path = /usr/sbin/sendmail -t -i

按 Esc 键退出编辑,输入 :wq 保存退出

重启php-fpm进程 /etc/init.d/php-fpm restart

 

如果还没安装php当然就没有/usr/local/php/etc/php.ini或者/etc/php.ini文件了,

安装:yum -y install php

php-cgi restart

 

9、补充2:通过以上配置,就可以正常发送邮件了,但是发件人邮箱会是 [email protected] 这种类型,如果想修改 www 这个参数,比如修改为 [email protected] 需要按照下面的步骤操作:

编辑 /etc/postfix/canonical:

vi /etc/postfix/canonical

添加下面类型的代码:

www [email protected]

保存退出,然后进入到 /etc/postfix/ 目录:

cd /etc/postfix/

执行命令:

postmap canonical

接着编辑 /etc/postfix/main.cf:

vi /etc/postfix/main.cf

一般情况下里面没有canonical_maps这个参数,在空行处添加:

canonical_maps = hash:/etc/postfix/canonical

保存退出,然后重启 postfix:

postfix reload

再次发送邮件测试,奇迹应该就发生啦!

10、补充3:通过上面的设置,虽然可以正常发送邮件,但是建议添加 DNS 解析,以减少被判定为垃圾邮件的几率。通常需要添加3个解析:A记录、MX记录、TXT记录,比如这里的 wpdaxue.com 域名的解析如下:

 

这样就好多了,最后,推荐使用下面的网站来测试你的服务器发送的邮件所得分数,它会给出详细的测试结果和改进方法:

 

 

问题:

1.postdrop: warning: unable to look up public/pickup: No such file or directory

解决 mkfifo /var/spool/postfix/public/pickup

2. postqueue: warning: unable to look up public/qmgr: No such file or directory

解决 mkfifo /var/spool/postfix/public/qmgr

3.postqueue: fatal: Cannot flush mail queue - mail system is down

原因:可能25端口被占用 

lsof -i:25 如果有占用程序 kill -9 PID 杀了那个程序重启 postfix

4. 给腾讯邮箱发邮件报错:status=bounced (host mx3.qq.com[183.57.48.35] said: 550 Ip frequency limited. http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=20022&&no=1000725 (in reply to end of DATA command))

解决:在腾讯邮箱中设置白名单

 

 

 第一个设置个人,第二个设置域

 

 5. status=bounced (unknown user: "kefu.czj")

解决:vim /etc/postfix/main.cf

mydestination = $mynetworks, $myhostname, localhost.$mydomain, localhost, $mydomain 这一行中

$mydomain和虚拟域名冲突了,当邮件发过来时会优先找mydestination的域名,而mydestination里的域名中是没有这些用户的,因而找不到用户名。

解决办法就是把$mydomain和$myhostname删除,或者改为不和虚拟域名一样

 

6.status=bounced (host mxn.mxhichina.com[42.120.219.27] said: 502 Mailfrom account is a local account [email protected] (in reply to MAIL FROM command))

原因:对方的邮件地址,使用的是万网的企业邮局,而发信人用的也是万网注册的域名,加上退信的内容是Mialfrom account is a local account,这样就表明,发信人的域名存在了万网的邮件服务器上,这样发信人自架的邮件发信过去,就自然会提示这个错误了。

 办法一:换一个域名

办法二(没亲测):就是删除万网上的企业邮件即可,即在万网的邮件服务器上不要有你的那个邮件域。

 

20140401221527.jpg

其它错误:

1.status=bounced (host mx54.dns.com.cn[220.181.130.176]said: 550 Does not like recipient,your mail is rejected! (in reply to end of DATA command)); sender non-delivery notification: F20F2DD80FC;removed

出错原因:对方某一台收件服务器当时正处在繁忙之中或者我们的服务器和对方链接并不是很顺畅

解决方法:有可能是暂时的情况,用别的地址测试一下,看看是否被退信,或者过一段时间再发送一下

 

2.status=bounced (host 192.168.21.20[192.168.21.20] said: 552 5.2.2 Over quota (in reply to end of DATA command));

出错原因:对方邮箱空间已满

解决方法:对方清理邮箱重新发送

 

3.1)status=bounced(hostmx3.qq.com[183.60.2.53]said:550Mailboxnotfound.http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=20022&&no=1000728 (in reply to RCPT TO command)); sender non-delivery notification: 9CC7FDD8084; removed

3.2)status=bounced (host 163mx01.mxmail.netease.com[220.181.12.62] said: 550 User not found: [email protected] (in reply to RCPT TO command)); sender non-delivery notification: 8FD7CA00013A; removed

出错原因:收件人地址不存在或者收件人地址写错

解决方法:核对地址后重新发送

 

4.status=deferred(hostmxzwg4.mxhichina.com[58.68.254.104]said:450MI:IPBhttp://www.net.cn/service/faq/youx/mailsy/200905/3781.html (in reply to MAIL FROM command))

出错原因:450MI:IPB发信IP被暂时禁止,请检查是否有用户发送病毒或者垃圾邮件。

解决方法:联系您的企业邮箱运营商

 

5.status=deferred(connecttoapllo-zm.com[60.191.124.236]:25:Connectiontimedout);from=<[email protected]>, size=24500463, nrcpt=2 (queue active);

出错原因:与对方邮箱服务器连接超时

解决方法: 首先确认对方邮箱地址中的域名部分是否写错,如果没错,telnet对方邮箱ip的25端口是否连接,如果连接正常,那么基本上是暂时的网络问题。

6.1)status=bounced (host sohumx1.sohu.com[220.181.26.202] said: 553 5.7.3 CONTENT REJECT:10.10.71.82.2011062016.XXD6ywq8:dspam check:5:http://mail.sohu.com/info/policy/12 (in reply to end of DATA command));

6.2)Recipient address rejected: User unknown in local recipient table

出错原因:1)内容被拒绝,可能是收件人对所接收的邮件进行了设置,内容中含有特定词汇等会被拒绝

              2)收件人地址被拒绝

解决方法:核实对方是否对内容及账户进行了设置之后重新发送

 

7.Clienthostrejected: Access denied; from=<[email protected]> to=<[email protected]> proto=SMTP helo=<hjy1>

出错原因:客户端主机被拒绝

解决方法:看一下客户端接收邮件服务器设置是否正确,“我的服务器需要身份验证”是否打钩,测试一下发信25口是否已连接

 

8. status=bounced (host mx1.mail.cnb.yahoo.com[203.209.228.250] said: 554 delivery error: dd Sorry your message to [email protected] cannot be delivered. This account has been disabled or discontinued [#102]. - mta1004.mail.cnb.yahoo.com (in reply to end of DATA command)); sender non-delivery notification: 1C580DD80B4; removed

出错原因:对方账号被停用或者不可用

解决方法:正常退信,换账号发送

 

9.status=bounced (message size 24864357 exceeds size limit 10240000 of server cluster4.us.messagelabs.com[98.126.139.202]); sender non-delivery notification: C6A3BDD8078; removed

出错原因:邮件过大,超出对方单封邮件接收范围(已解决)

解决方法:对方换账号,重新发送

10. status=bounced (host 163mx03.mxmail.netease.com[220.181.12.90] said: 552 Requested mail action aborted: exceeded mailsize limit (in reply to end of DATA command));

出错原因:发送的信件大小超过了网易邮箱允许接收的最大限制

解决方法:把附件压缩或者分次发送或者换其他邮箱接收

 

11. <[email protected]>: host mail.messaging.microsoft.com[216.32.180.22] said:

  550 5.7.1 Service unavailable; Client host [98.126.139.202] blocked using Blocklist 2, mail from IP banned; To request removal from this list please forward this message to [email protected] (in reply to RCPT TO command)

Reporting-MTA: dns; hw.upanshi.com

X-Postfix-Queue-ID: CC2D4681FD

X-Postfix-Sender: rfc822; [email protected]olab.com

Arrival-Date: Thu, 13 Oct 2011 19:48:18 -0700 (PDT)

Final-Recipient: rfc822; [email protected]

Original-Recipient: rfc822;[email protected]

退信原因:ip被列入黑名单

解决方法:根据退信提示解封ip