CentOS 系统下Postfix邮件系统配置

硬件环境:

服务器型号:IBMX336

CPU型号:Intel(R)Xeon(TM)CPU3.80GHz*2颗

内存型号:2G*4根

硬盘型号:SCSI73G*2块

软件配置:

系统:CentOS5.6x86_64

软件:Nginx1.0.4+PHP5.3.6(FPM-FCGI)+Mysql5.5.3

Linux系统最小安装,在此就不多说了。此机器主要功能是对外进行图片访问,由于公司需要邮件系统进行邮件发送和接收,考虑Qmail配置太复杂,sendmail配置也麻烦所以就选择postfix作为邮件处理系统。

1.PostFix安装配置

2.dovecot安装配置

3.防火墙配置

4.测试邮件发送

1.PostFix安装配置

第一步:首先进行安装postfix

yum-yinstallpostfix

第二步:配置main.cf文件

[root@kiccleaf~]#vim/etc/postfix/main.cf

myhostname=mail.kiccleaf.com

mydomain=kiccleaf.com

myorigin=$mydomain

inet_interfaces=all

mydestination=$myhostname,localhost.$mydomain,localhost,$mydomain

relay_domains=$mydestination

mynetworks=192.168.1.0/28,127.0.0.0/8,60.191.49.228/24#填写自己的公网ip

home_mailbox=Maildir/

#smtpd_banner=$myhostnameESMTP$mail_name($mail_version) ←找到这一行,接此行添加如下行:

smtpd_banner=$myhostnameESMTPunknow←添加这一行,不显示SMTP服务器的相关信息

#Addend

smtpd_sasl_auth_enable=yes

smtpd_sasl_local_domain=$myhostname

smtpd_sasl_security_options=noanonymous

smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

message_size_limit=15728640

第三步:配置smtpd.conf

[root@kiccleaf~]#vim/usr/lib64/sasl2/smtpd.conf

有的默认地址可能不是这个,具体find一下

pwcheck_method:saslauthd

改成

pwcheck_method:auxprop

第四步:配置postfix随系统启动

[root@kiccleaf~]#chkconfigsaslauthdon

[root@kiccleaf~]#chkconfig--listsaslauthd

saslauthd0:off1:off2:on3:on4:on5:on6:off

[root@kiccleaf~]#chkconfigpostfixon

[root@kiccleaf~]#chkconfig--listpostfix

postfix0:off1:off2:on3:on4:on5:on6:off

第五步:启动postfix服务

[root@kiccleaf~]#/etc/rc.d/init.d/saslauthdstart

Startingsaslauthd:[OK]

[root@kiccleaf~]#/etc/rc.d/init.d/postfixstart

Startingpostfix:[OK]

第六步:对postfix进行测试

telnetlocalhost25

Trying127.0.0.1...

Connectedtolocalhost.localdomain(127.0.0.1).

Escapecharacteris'^]'.

220kiccleaf.comESMTPunknow

ehlolocalhost

250-kiccleaf.com

250-PIPELINING

250-SIZE15728640

250-VRFY

250-ETRN

250-AUTHPLAINLOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250DSN

quit

2212.0.0Bye

Connectionclosedbyforeignhost.

第七步:添加配置,用户和密码

[root@kiccleaf~]#mkdir/data/Maildir

[root@kiccleaf~]#chmod700/data/Maildir

[root@kiccleaf~]#mkdir/home/leaf/Maildir

[root@kiccleaf~]#chmod700/home/leaf/Maildir

[root@kiccleaf~]#chownleaf./home/leaf/Maildir

[root@kiccleaf~]#saslpasswd2-umail.kiccleaf.com-cleaf#添加帐号leaf

Password:#输入密码

Again(forverification):#输入重复密码

[root@kiccleaf~]#chgrppostfix/etc/sasldb2

[root@kiccleaf~]#chmod640/etc/sasldb2

[root@kiccleaf~]#alternatives--configmta

Thereare2programswhichprovide'mta'.

SelectionCommand

-----------------------------------------------

*+1/usr/sbin/sendmail.sendmail

2/usr/sbin/sendmail.postfix

Entertokeepthecurrentselection[+],ortypeselectionnumber:2#选择postfix作为邮件服务

2.接下去安装pop3接收服务dovecot

第一步:dovecot服务安装

yum-yinstalldovecot

第二步:编辑dovecot.conf文件

找到#protocols=imapimapspop3pop3s行添加或是修改:

protocols=imappop3

老版本CentOS5.5版本是以default_mail_env作为配置

mail_location=maildir:~/Maildir

第三步:配置dovecot随系统启动

[root@kiccleaf~]#chkconfigdovecoton

[root@kiccleaf~]#chkconfig--listdovecot

dovecot0:off1:off2:on3:on4:on5:on6:off

第四步:启动dovecot服务

[root@kiccleaf~]#/etc/rc.d/init.d/dovecotstart

StartingDovecotImap:[OK]

第五步:对dovecot进行测试

telnetlocalhost110

Trying127.0.0.1...

Connectedtolocalhost.localdomain(127.0.0.1).

Escapecharacteris'^]'.

+OKDovecotready.

quit

+OKLoggingout

Connectionclosedbyforeignhost.

3.防火墙配置

[root@kiccleaf~]#vim/etc/sysconfig/iptables

#添加以下三个端口25,110,143

-AINPUT-mstate--stateNEW-mtcp-ptcp--dport25-jACCEPT

-AINPUT-mstate--stateNEW-mtcp-ptcp--dport110-jACCEPT

-AINPUT-mstate--stateNEW-mtcp-ptcp--dport143-jACCEPT

#重启防火墙

[root@kiccleaf~]#serviceiptablesrestart

Flushingfirewallrules:[OK]

SettingchainstopolicyACCEPT:filter[OK]

Unloadingiptablesmodules:[OK]

Applyingiptablesfirewallrules:[OK]

Loadingadditionaliptablesmodules:ip_conntrack_netbios_n[OK]

#查看监听端口列表

[root@kiccleaf~]#netstat-an

ActiveInternetconnections(serversandestablished)

ProtoRecv-QSend-QLocalAddressForeignAddressState

tcp00127.0.0.1:90000.0.0.0:*LISTEN

tcp000.0.0.0:21880.0.0.0:*LISTEN

tcp000.0.0.0:1100.0.0.0:*LISTEN

tcp000.0.0.0:1430.0.0.0:*LISTEN

tcp000.0.0.0:800.0.0.0:*LISTEN

tcp000.0.0.0:580080.0.0.0:*LISTEN

tcp00127.0.0.1:250.0.0.0:*LISTEN

tcp00192.168.1.9:22192.168.1.22:2850ESTABLISHED

4.测试邮件发送

为了方便Foxmail作为客户端进行配置,填写ip为pop3,smtp,填写帐号名称及密码,进行发送测试,在此用php编写简要的发送代码进行测试。

<?php

$to='53045936@qq.com';

$subject='thesubjecttest';

$message='hello!测试用例!';

$headers='From:leaf@kiccleaf.com'."\r\n".

'Reply-To:leaf@kiccleaf.com'."\r\n".

'X-Mailer:PHP/'.phpversion();

mail($to,$subject,$message,$headers);

?>

至此邮件系统的发送和接收都已经配置完成

出处:http://www.kiccleaf.com/?p=94

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

另外:

使postfix邮件服务器支持多域名

需求:

假设现在我有两个这样的域名kavin.com和kavin.cn。现在kavin.com作为主域名已经成功地在ip地址为125.168.2.16的服务器上配置了postfix。即可以通过abc@kavin.com发送和接收邮件。现在希望kavin.cn域名也指向该服务器,并可以通过abc@kavin.cn发送和接收邮件,并且两个域名对应的用户是一致的,即发送给abc@kavin.com的邮箱的用户实际上也是给abc@kavin.cn邮箱的用户的邮件,而同一个用户abc可以选择使用abc@kavin.com或者abc@kavin.cn发送邮件,而接收方看到的是不同的域名发出来的邮件。

够啰嗦了,好,马上开始吧。

一、对postfix的虚拟域名相关选项进行设置

$vi/etc/postfix/main.cf

virtual_alias_maps=hash:/etc/postfix/virtual

二、定义虚拟域名转换规则

$vi/etc/postfix/virtual//在文件末尾添加上下面两行

kavin.cnanything

@kavin.cn@kavin.com

三、更新虚拟域名规则

$postmap/etc/postfix/virtual

四、重启postfix

$servicepostfixrestart

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

另外一些有用的postfix维护命令,一遍日常的检测和维护:

mailq:会列出当前在postfix发送队列中的所有邮件

postsuper-dALL:删除当前等待发送队列的所有邮件,包括发送失败的退信

当然还有很多,就不一一列举了,大家可以网上搜索扩展,GoodLuck!

==========================

记得开通域名mx记录

相关推荐