构建简单电子邮件系统
Postfix:提供邮件发送服务(SMTP) Dovecot:提供邮件收取服务(POP3)Foxmail:用于收发信的客户端工具
#配置好本地DNS服务器
#修改主机名
[root@mail ~]# vim /etc/sysconfig/network
[root@mail ~]# cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=mail.sxkj.com#修改hosts文件
[root@mail ~]# vim /etc/hosts[root@mail ~]# cat /etc/hosts10.0.1.88 mail mail.sxkj.com::1 mail mail.sxkj.com [root@mail ~]# hostname mail.sxkj.com#修改DNS配置文件
[root@mail postfix]# cp -a /var/named/163.com.zone /var/named/sxkj.com.zone[root@mail postfix]# vim /var/named/sxkj.com.zone[root@mail postfix]# cat /var/named/sxkj.com.zone$TTL 1D@ IN SOA mail.sxkj.com. root (3 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimum@ IN NS mail.sxkj.com.@ IN A 10.0.1.88www IN A 10.0.1.88mail IN A 10.0.1.88@ IN MX 5 mail.sxkj.com.
#重启DNS服务
[root@mail postfix]# service named restart
Stopping named: . [ OK ]Starting named: [ OK ]
#安装Postfix
#停用sendmail服务,以避免冲突[root@mail ~]# yum install postfix -y[root@mail ~]# alternatives --config mtaThere is 1 program that provides 'mta'.Selection Command-----------------------------------------------*+ 1 /usr/sbin/sendmail.postfixEnter to keep the current selection[+], or type selection number: 1
#重启postfix服务
[root@mail ~]# service postfix restartShutting down postfix: [ OK ]Starting postfix: [ OK ]
#开机启动,查看25号端口是否开启
[root@mail ~]# chkconfig postfix on[root@mail ~]# netstat -ntpl | grep 25tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 19481/mastertcp 0 0 ::1:25 :::* LISTEN 19481/master
#修改配置文件main.cf
[root@mail ~]# cd /etc/postfix/[root@mail postfix]# postconf -n >main.cf.new[root@mail postfix]# mv main.cf main.cf.old[root@mail postfix]# mv main.cf.new main.cf[root@mail postfix]# vim main.cf[root@mail postfix]# tail -5 main.cf
#修改以下选项
inet_protocols = allinet_protocols = ipv4#添加以下选项myorigin = $mydomainmyhostname = mail.sxkj.commydomain = sxkj.comhome_mailbox = Maildir/mydestination = $mydomain,$myhostname, localhost.$mydomain, localhostmynetworks = 127.0.0.1#添加本地用户
[root@mail ~]# useradd user1[root@mail ~]# useradd user2[root@mail ~]# passwd user1[root@mail ~]# passwd user2
#telnet进行测试
[root@mail ~]# yum install telnet -y[root@mail ~]# telnet 10.0.1.88 25Trying 10.0.1.88...Connected to 10.0.1.88.Escape character is '^]'.220 mail.sxkj.com ESMTP Postfixmail from:user1250 2.1.0 Okrcpt to:user2250 2.1.5 Okdata354 End data with. subject:user1 to user21111111111111.250 2.0.0 Ok: queued as 74A69C1766quit221 2.0.0 ByeConnection closed by foreign host.
#查看是否收到成功收到邮件
[root@mail ~]# cat /home/user2/Maildir/new/1376117066.Vfd00I63167M572286.mail.sxkj.comReturn-Path:X-Original-To: user2Delivered-To: user2@sxkj.comReceived: from mail (mail [10.0.1.88])by mail.sxkj.com (Postfix) with SMTP id 8E04DC4C1Afor ; Sat, 10 Aug 2013 14:43:55 +0800 (CST)subject:user1 to user2Message-Id: <20130810064402.8E04DC4C1A@mail.sxkj.com>Date: Sat, 10 Aug 2013 14:43:55 +0800 (CST)From: user1@sxkj.comTo: undisclosed-recipients:;1111111111111
#yum安装dovecot软件
[root@mail ~]# yum install dovecot -y
#修改配置文件
[root@mail ~]# vim /etc/dovecot/dovecot.conf[root@mail ~]# tail -5 /etc/dovecot/dovecot.conflisten = *ssl_disable = yesprotocols = pop3 imapdisable_plaintext_auth = nomail_location = maildir:~/Maildir
#POP3收信测试:telnet localhost 110
[root@mail ~]# telnet mail 110
Trying ::1...
telnet: connect to address ::1: Connection refusedTrying 10.0.1.88...Connected to mail.Escape character is '^]'.+OK Dovecot ready.USER user1+OKPASS 123+OK Logged in.LIST+OK 1 messages:1 518.RETR 1+OK 518 octetsReturn-Path: <>X-Original-To: user1Delivered-To: Received: by mail.sxkj.com (Postfix, from userid 0) id 0C3E4C1766; Sat, 10 Aug 2013 14:37:14 +0800 (CST)Date: Sat, 10 Aug 2013 14:37:14 +0800To: Subject: root to user1User-Agent: Heirloom mailx 12.4 7/29/08MIME-Version: 1.0Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitMessage-Id: <>From: (root)222222222222222222222
. #源码安装squirrelmail程序套件[root@mail ~]# tar xf squirrelmail-1.4.18.tar.gz [root@mail ~]# mv squirrelmail-1.4.18 /var/www/html/webmail[root@mail ~]# cd /var/www/html/webmail/[root@mail webmail]# tar xf zh_CN-1.4.18-20090526.tar.gz [root@mail webmail]# chown apache:apache data/[root@mail webmail]# cp config/config_default.php config/config.php[root@mail webmail]# vim config/config.php$squirrelmail_default_language = 'zh_CN';
$default_charset = 'zh_CN.UTF-8';$domain = 'sxkj.com';$data_dir = '/var/www/html/webmail/data/';$p_w_upload_dir = '/var/www/html/webmail/attach/';[root@mail ~]# vim /etc/httpd/conf.d/vhost.conf
[root@mail ~]# tail -4 /etc/httpd/conf.d/vhost.conf <VirtualHost 10.0.1.88:80> DocumentRoot /var/local/squirrelmail/ ServerName mail.sxkj.com</VirtualHost> [root@mail squirrelmail]# service httpd restartStopping httpd: [ OK ]Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using mail.sxkj.com for ServerName [ OK ][root@mail squirrelmail]# service mysqld restartStopping mysqld: [ OK ]Starting mysqld: [ OK ]