---参考文章:http://blog.csdn.net/winscar/article/details/6483322

--->postfix+squirrelmail邮件系统

------------------------->debian6 系统

----------------------------->  vmware 7 虚拟机

--------------------------------------------->  windows 7系统

############

1.安装系统

debian系统是pxe网络安装的----关于安装debian系统之前有一片文章写下来了

---

安装完成之后需要为后续安装的虚拟系统做准备。最主要的是虚拟连接的配置,这里就着重介绍下虚拟连接的配置过程。

在默认情况下,在虚拟机安装成功之后,系统会自动添加两个虚拟连接:VMNET1VMNET8。我们对它们的IP地址和网关暂时先不进行配置。先打开虚拟机,在菜单Edit下点开Virtual network editor。在summary标签下我们可以看到虚拟机建立的虚拟连接,它们有各自的作用。这里以NAT为例介绍配置过程。

点开NAT标签,在VMnet host下拉框内选择VMnet8(选择其他也可以,只是在后期的配置过程中有所不同)。点击应用了之后,可以看到普通情况下不可修改的Gateway ip address,记录下来。之后一路确定退出。然后回头在系统网络连接里修改VMnet8IP地址,子网掩码以及网关。将网关改成刚刚记录的那个网关,子网掩码自动生成,IP地址改成与该网关同网段的IP即可(不得与网关重IP)。

到此这个步骤结束。

 

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

2.安装邮件系统软件包

root@debian:# apt-get install postfix libsasl2-2 sasl2-bin libsasl2-modules dovecot-imapd dovecot-pop3d dovecot-common

接下来,系统会检查网络进行连接,下载并安装软件包等。安装过程中会询问关于邮件服务器的设置,此处由于要提供对外网的邮件接受发送服务,所以选择internet site。这中间任何一个软件包的安装都不能出错,如果出错请根据提示进行检查安装,否则会影响后期配置。

在安装完成之后,我们进入配置阶段

 

 

3 配置邮件服务器

  首先,停掉这三项服务:

  sudo /etc/init.d/saslauthd stop

  sudo /etc/init.d/postfix stop

  sudo /etc/init.d/dovecot stop

 

  

  接下来,修改postfix的配置文件/etc/postfix/main.cf

 

  由于采用了sasl做认证,同时用dovecot作为pop3imapsmtp的服务,所以需要修改postfix的配置文件以适应需求。

  在/etc/postfix/main.cf文件中增加以下信息以支持sasl认证和dovecot服务。

 

  smtpd_sasl_type = dovecot

  smtpd_sasl_path = private/auth

  smtpd_sasl_auth_enable = yes

  smtpd_sasl_local_domain = yourdomain.com

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

  smtpd_sasl_security_options = noanonymous

 

  另外main.cf中的以下两个参数

  myhostname = yourhostname

  mydestination = yourdomain.com, localhost.localdomain, localhost

  分别代表了你的服务器信息,myhostname是你当前主机名,mydestination其中的yourdomain.com则是邮件服务器名。

 

  修改完毕后保存该文件。

 

  

  接下来,修改/etc/dovecot/dovecot.conf文件

  修改参数protocols

  protocols = pop3 imap

  设置参数disable_plaintext_auth

  disable_plaintext_auth = no

  找到auth default,将auth default改名为auth default2

  然后在这行前面增加如下信息

auth default {

mechanisms = plain login

passdb pam {

}

userdb passwd {

}

socket listen {

client {

path = /var/spool/postfix/private/auth

mode = 0660

user = postfix

group = postfix

}

 

}

}

  注意:这里的每个‘{’前都有个空格。

  然后保存该文件。

 

 

  接下来,修改sasl配置文件。

  debian默认的安装配置中sasl并不会自动启动,需要修改/etc/default/saslauthd文件。

  将其中的START=no修改为START=yes

  修改

  OPTIONS="-c -m /var/run/saslauthd"

  为

  OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

  然后保存该文件。

 

 

  在启用sasl的情况下postfix运行需要sasldb2文件在postfixchroot环境中。

  同时为了保证saslauthd能和postfix通讯,需要作如下的修改。

 

  删除位于/va/run目录下的saslauthd目录,然后创建一个指向/var/spool/postfix/var/run/saslauthd的符号连接。

 

  sudo rm -r /var/run/saslauthd/

 

  sudo mkdir -p /var/spool/postfix/var/run/saslauthd

 

  sudo ln -s /var/spool/postfix/var/run/saslauthd /var/run

 

  sudo chgrp sasl /var/spool/postfix/var/run/saslauthd

 

  sudo adduser postfix sasl

 

  另外postfix在运行的时候需要将/etc/sasldb2文件拷贝到chroot环境中。

  修改/etc/init.d/postfix文件,修改其中的FILES变量,在其中增加etc/sasldb2

 

 

  完成以上工作后启动三个服务。

  sudo /etc/init.d/saslauthd start

  sudo /etc/init.d/postfix start

  sudo /etc/init.d/dovecot start

  然后新增用户

  adduser username

 

  至此,邮件服务器的配置成功。

 

4.配置squirrelMail

在终端输入命令以下载安装squirrelMail

命令如下:

#apt-get install squirrelmail

之后会提示安装,安装成功后我们进入配置阶段。

 

打开squirrelmail的配置工具,在终端输入:

1.#/usr/share/squirrelmail/config/conf.pl

2.Command>>d

3.设置IMAP服务器类型名为:dovecot

4.Command>>2

5.domain改成yourdomainnamesendmail or SMTP改成SMTP

6.Command>>s

 

Squirrelmail的基本配置完成,现在可以通过浏览器查看网页邮箱了。在这之前,还需要配置下apache2。配置如下:

#cd /etc/apache2

#vim apache2.conf

然后在打开的文件内部添加下面这一行

Include /etc/squirrelmail/apache.conf

#/etc/init.d/apache2 restart

 

至此,配置结束

 

5.测试

利用命令

#adduser username

在服务器内部添加几个用户,利用这几个用户来测试邮件服务器是否配置成功。

打开浏览器,输入网址http://yourdomainname/squirrelmail 进行测试。

 

 

 

6.附加注意

 

  配置完上述的服务器只是个开始,后面的所有调试部分是最需要配置者自行进行研究的部分。在上述配置完成后,后续的调试极少有直接成功的,在不成功的情况下,希望大家自行利用各种工具和手段进行故障排除和问题解决。下面给出一些建议:

  1.查询系统邮件日志文件:/var/log/mail.log

  2.查询各种配置文件:/etc/postfix/main.cf    /etc/dovecot/dovecot.conf    /etc/apache/apache.conf    ……

  3.谷歌,雅虎,百度……

 

  在配置dovecot.conf重启服务后一直报错,用测试账号登陆http://域名/squirrelmail--- 报错登陆不上,之后按一下内容修改后可以访问了,但是重启dovecot服务还是会有错误提示---

##########
在 dovecot.conf 添加了如下一句:

    mail_location = mbox:~/mail:INBOX=/var/mail/%u

  在 main.cf 注释掉了如下这句:

    mailbox_command = procmail -a "$EXTENSION"

部分配置文件如下所示》

root@debian:~# vi /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
/mailbox

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = debian.guo

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

smtpd_sasl_security_options = noanonymous

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = debian.guo
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = debian.guo, localhost.guo, , localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128mailbox_command = procm
ail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
root@debian:~# vi /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
/mailbox

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = debian.guo

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

smtpd_sasl_security_options = noanonymous

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

myhostname = debian.guo
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = debian.guo, localhost.guo, , localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
"/etc/postfix/main.cf" 51L, 1551C written                    
root@debian:~# /etc/init.d/saslauthd start
Starting SASL Authentication Daemon: saslauthd (already running).
root@debian:~# /etc/init.d/postfix start
Starting Postfix Mail Transport Agent: postfix.
root@debian:~# /etc/init.d/dovecot start
doveconf: Warning: NOTE: You can get a new clean config file with: doveconf -n > dovecot-new.conf
doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:4: add auth_ prefix to all settings inside auth {} and remove the auth {} section completely
doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:8: passdb pam {} has been replaced by passdb { driver=pam }
doveconf: Warning: Obsolete setting in /etc/dovecot/dovecot.conf:12: userdb passwd {} has been replaced by userdb { driver=passwd }
Starting IMAP/POP3 mail server: dovecot.
root@debian:~#