CentOS 系统下Postfix邮件系统配置

硬件环境:
服务器型号: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文件

[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 = $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
[root@kiccleaf ~]# vim /usr/lib64/sasl2/smtpd.conf
有的默认地址可能不是这个,具体find一下
pwcheck_method: saslauthd
改成
pwcheck_method: auxprop

第四步:配置postfix随系统启动
[root@kiccleaf ~]# chkconfig saslauthd on
[root@kiccleaf ~]# chkconfig --list saslauthd
saslauthd       0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@kiccleaf ~]# chkconfig postfix on
[root@kiccleaf ~]# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off

第五步:启动postfix服务
[root@kiccleaf ~]# /etc/rc.d/init.d/saslauthd start
Starting saslauthd:                                        [  OK  ]

[root@kiccleaf ~]# /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.


第七步:添加配置,用户和密码
[root@kiccleaf ~]# mkdir /data/Maildir
[root@kiccleaf ~]# chmod 700 /data/Maildir
[root@kiccleaf ~]# mkdir /home/leaf/Maildir
[root@kiccleaf ~]# chmod 700 /home/leaf/Maildir
[root@kiccleaf ~]# chown leaf. /home/leaf/Maildir
[root@kiccleaf ~]# saslpasswd2 -u mail.kiccleaf.com -c leaf  #添加帐号leaf
Password:          #输入密码
Again (for verification):    #输入重复密码
[root@kiccleaf ~]# chgrp postfix /etc/sasldb2
[root@kiccleaf ~]# chmod 640 /etc/sasldb2
[root@kiccleaf ~]# 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随系统启动
[root@kiccleaf ~]# chkconfig dovecot on
[root@kiccleaf ~]# chkconfig --list dovecot
dovecot         0:off   1:off   2:on    3:on    4:on    5:on    6:off

第四步:启动dovecot服务
[root@kiccleaf ~]# /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.防火墙配置

[root@kiccleaf ~]# 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

#重启防火墙
[root@kiccleaf ~]# 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  ]
#查看监听端口列表
[root@kiccleaf ~]# 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);
?>


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

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



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

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

需求:

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



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



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

$ vi /etc/postfix/main.cf

virtual_alias_maps=hash:/etc/postfix/virtual

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

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

kavin.cn anything

@kavin.cn @kavin.com

三、更新虚拟域名规则

$ postmap /etc/postfix/virtual

四、重启postfix

$ service postfix restart



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

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

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

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

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


==========================
记得开通域名mx记录

猜你喜欢

转载自zlr.iteye.com/blog/2103966