平淡人生

静待花开,花开常有香相伴;倾听流水,流水总有乐相陪;有缘清风携舟涉碧水,无缘细雨伴君独自行。

CentOS 5.6 X86_64系统下Postfix邮件系统配置【pop3,smtp】

硬件环境:
服务器型号:IBM X336
CPU型号: Intel(R) Xeon(TM) CPU 3.80GHz *2颗
内存型号: 2G*4根
硬盘型号:SCSI 73G*2块

软件配置:
系统:CentOS5.6 x86_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 -y install postfix

第二步:配置main.cf文件

[[email protected] ~]# 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 = $myhostname ESMTP $mail_name ($mail_version)  ← 找到这一行,接此行添加如下行:
smtpd_banner = $myhostname ESMTP unknow ← 添加这一行,不显示SMTP服务器的相关信息

#Add end
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

[[email protected] ~]# vim /usr/lib64/sasl2/smtpd.conf

pwcheck_method: saslauthd
改成
pwcheck_method: auxprop

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

[[email protected] ~]# chkconfig saslauthd on
[[email protected] ~]# chkconfig --list saslauthd
saslauthd      	0:off	1:off	2:on	3:on	4:on	5:on	6:off

[[email protected] ~]# chkconfig postfix on
[[email protected] ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

第五步:启动postfix服务

[[email protected] ~]# /etc/rc.d/init.d/saslauthd start
Starting saslauthd:                                        [  OK  ]

[[email protected] ~]# /etc/rc.d/init.d/postfix start
Starting postfix:                                          [  OK  ]

第六步:对postfix进行测试

telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 kiccleaf.com ESMTP unknow
ehlo localhost
250-kiccleaf.com
250-PIPELINING
250-SIZE 15728640
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

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

 [[email protected] ~]# mkdir /data/Maildir
 [[email protected] ~]# chmod 700 /data/Maildir
 [[email protected] ~]# mkdir /home/leaf/Maildir
 [[email protected] ~]# chmod 700 /home/leaf/Maildir
 [[email protected] ~]# chown leaf. /home/leaf/Maildir
 [[email protected] ~]# saslpasswd2 -u mail.kiccleaf.com -c leaf  #添加帐号leaf
 Password:          #输入密码
 Again (for verification):    #输入重复密码
 [[email protected] ~]# chgrp postfix /etc/sasldb2
 [[email protected] ~]# chmod 640 /etc/sasldb2
 [[email protected] ~]# alternatives --config mta

There are 2 programs which provide 'mta'.

Selection Command
 -----------------------------------------------
 *+ 1 /usr/sbin/sendmail.sendmail
 2 /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2      #选择postfix作为邮件服务
 

2.接下去安装pop3接收服务dovecot
第一步:dovecot服务安装

yum -y install dovecot

第二步:编辑dovecot.conf文件

找到#protocols = imap imaps pop3 pop3s行添加或是修改:
protocols = imap pop3
老版本CentOS5.5版本是以default_mail_env作为配置
mail_location = maildir:~/Maildir

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

[[email protected] ~]# chkconfig dovecot on
[[email protected] ~]# chkconfig --list dovecot
dovecot        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

第四步:启动dovecot服务

[[email protected] ~]# /etc/rc.d/init.d/dovecot start
Starting Dovecot Imap:                                     [  OK  ]

第五步:对dovecot进行测试

telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
quit
+OK Logging out
Connection closed by foreign host.

3.防火墙配置

[[email protected] ~]# vim /etc/sysconfig/iptables
#添加以下三个端口25,110,143
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

#重启防火墙
[[email protected] ~]# service iptables restart
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
Applying iptables firewall rules:                          [  OK  ]
Loading additional iptables modules: ip_conntrack_netbios_n[  OK  ]
#查看监听端口列表
[[email protected] ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:2188                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:58008               0.0.0.0:*                   LISTEN
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 192.168.1.9:22           192.168.1.22:2850           ESTABLISHED

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

<?php
$to      = '[email protected]';
$subject = 'the subject test';
$message = 'hello!测试用例!';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To:  [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

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

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


Categorised as: linux 技术