搭建postfix邮件服务器建议在此之前配置一个DNS服务器,如果你不是在内部测试的话那就没有这个必要,将DNS指到公网的DNS服务器即可,同时要做好域名解析
我使用的是redhat 5.4 服务器系统
---------------
关闭sendmail服务:
我们都知道linux上有默认的sendmail,我们要关闭他
[root@mail ~]# service sendmail stop
关闭  sm-client:                    [确定]
关闭  sendmail:                     [确定]
[root@mail ~]# chkconfig sendmail off
---------------
创建用户:
一个好的管理员,都会为每一个服务配置一个专有的管理账户postfix也不例外
[root@mail ~]# groupadd -g 1200 postdrop
[root@mail ~]# groupadd -g 1000 postfix
[root@mail ~]# useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
---------------
解压源码包、合并补丁包:
[root@mail mail]# tar xzvf postfix-2.4.6.tar.gz 
[root@mail mail]# gunzip postfix-2.4.6-vda-ng.patch.gz 
[root@mail mail]# cd postfix-2.4.6
[root@mail postfix-2.4.6]# patch -p1 < ../postfix-2.4.6-vda-ng.patch     // -p1(1 为数字)
patching file README_FILES/VDA_README
patching file src/global/mail_params.h
patching file src/util/file_limit.c
patching file src/virtual/mailbox.c
patching file src/virtual/maildir.c
patching file src/virtual/virtual.c
patching file src/virtual/virtual.h
----------------
配置编译参数
[root@mail postfix-2.4.6]# cp ../postfix.sh ./
[root@mail postfix-2.4.6]# chmod a+x postfix.sh 
[root@mail postfix-2.4.6]# vim postfix.sh

make makefiles \
'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \
-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' \
'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2'

[root@mail postfix-2.4.6]# ./postfix.sh    //使用脚本进行编译前的配置
[root@mail postfix-2.4.6]# make
[root@mail postfix-2.4.6]# make install    //有提示直接回车接受默认配置
----------------
编辑main.cf配置文件,调整Postfix的基本运行参数:
[root@mail postfix-2.4.6]# cd /etc/postfix/
[root@mail postfix]# postconf -n > main2.cf
[root@mail postfix]# mv main.cf main.cf.bak
[root@mail postfix]# mv main2.cf main.cf
[root@mail postfix]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@mail postfix]# netstat -antp |grep :25 //查看服务
tcp  0  0 0.0.0.0:25    0.0.0.0:*      LISTEN       12738/master
[root@mail postfix]# vim main.cf

inet_interfaces = 192.168.1.1, 127.0.0.1    //添加下列各行,实际的需要根据实际情况去添加或更改
myhostname = mail.abc.com
mydomain = abc.com
myorigin = $mydomain
mydestination = $mydomain, $myhostname
home_mailbox = Maildir/ 

[root@mail postfix]# groupadd mailusers
创建连个用户,用于测试
[root@mail postfix]# useradd -g mailusers -s /sbin/nologin hou
[root@mail postfix]# useradd -g mailusers -s /sbin/nologin tom
[root@mail postfix]# passwd hou
[root@mail postfix]# passwd tom
[root@mail postfix]# postfix reload

到此postfix搭建到一段落,但是我们要添加一个服务模块我使用的是Dovecot
------------------
编译安装 Dovecot软件包
[root@mail mail]# useradd -M -s /sbin/nologin dovecot
[root@mail mail]# tar xzvf dovecot-1.1.4.tar.gz 
[root@mail mail]# cd dovecot-1.1.4
[root@mail dovecot-1.1.4]#
[root@mail dovecot-1.1.4]# ./configure --sysconfdir=/etc/ --with-mysql
[root@mail dovecot-1.1.4]# make
[root@mail dovecot-1.1.4]# make install
----------------------
建立 dovecot.conf配置文件:
[root@mail dovecot-1.1.4]# cp /etc/dovecot-example.conf /etc/dovecot.conf
[root@mail dovecot-1.1.4]# 
[root@mail dovecot-1.1.4]# vim /etc/dovecot.conf  //找到对应行数,复制后去掉#号修改,以防修改错误无法恢复原参数
23 #protocols = imap imaps
24 protocols = pop3 imap
 
48 #disable_plaintext_auth = yes
49 disable_plaintext_auth = no
 
87 #ssl_disable = no
88 ssl_disable = yes
 
211 #mail_location = maildir:~/Maildir
212 mail_location = maildir:~/Maildir

以上行号,是我根据我的服务器配置所显示的行号,如果此服务有更新版本,请大家自己查找
--------------------
创建PAM认证文件:
[root@mail dovecot-1.1.4]# 
[root@mail dovecot-1.1.4]# vim /etc/pam.d/doveco

auth       required       pam_nologin.so
auth       include        system-auth
account    include        system-auth
session    include        system-auth

--------------------
启动 Dovecot 服务,验证 TCP 端口(110,143)
[root@mail dovecot-1.1.4]# /usr/local/sbin/dovecot -c /etc/dovecot.conf 
[root@mail dovecot-1.1.4]#
[root@mail dovecot-1.1.4]# netstat -nutpl | grep dovecot
 
tcp  0  0 0.0.0.0:110       0.0.0.0:*      LISTEN    3425/dovecot   
tcp  0  0 0.0.0.0:143       0.0.0.0:*      LISTEN    3425/dovecot
--------------------
之后就可以使用之前创建的hou、tom这两个用户进行测试了,测试PC要把DNS指向我们自己所搭建的DNS服务,以保证邮件顺利收发