构建简单电子邮件系统


Postfix:提供邮件发送服务(SMTP) 
Dovecot:提供邮件收取服务(POP3)
Foxmail:用于收发信的客户端工具

 

#配置好本地DNS服务器

#修改主机名

[root@mail ~]# vim /etc/sysconfig/network
[root@mail ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mail.sxkj.com

#修改hosts文件
[root@mail ~]# vim /etc/hosts
[root@mail ~]# cat /etc/hosts
10.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 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@       IN      NS      mail.sxkj.com.
@       IN      A       10.0.1.88
www     IN      A       10.0.1.88
mail    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 mta
There is 1 program that provides 'mta'.
Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 1

#重启postfix服务

[root@mail ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]

#开机启动,查看25号端口是否开启

[root@mail ~]# chkconfig  postfix on
[root@mail ~]# netstat -ntpl | grep 25
tcp     0   0 127.0.0.1:25        0.0.0.0:*           LISTEN      19481/master
tcp     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 = all
inet_protocols = ipv4
#添加以下选项
myorigin = $mydomain
myhostname = mail.sxkj.com
mydomain = sxkj.com
home_mailbox = Maildir/
mydestination = $mydomain,$myhostname, localhost.$mydomain, localhost
mynetworks = 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 25
Trying 10.0.1.88...
Connected to 10.0.1.88.
Escape character is '^]'.
220 mail.sxkj.com ESMTP Postfix
mail from:user1
250 2.1.0 Ok
rcpt to:user2
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
subject:user1 to user2
1111111111111
.
250 2.0.0 Ok: queued as 74A69C1766
quit
221 2.0.0 Bye
Connection closed by foreign host.

#查看是否收到成功收到邮件

[root@mail ~]# cat /home/user2/Maildir/new/1376117066.Vfd00I63167M572286.mail.sxkj.com
Return-Path: <user1@sxkj.com>
X-Original-To: user2
Delivered-To: user2@sxkj.com
Received: from mail (mail [10.0.1.88])
by mail.sxkj.com (Postfix) with SMTP id 8E04DC4C1A
for <user2>; Sat, 10 Aug 2013 14:43:55 +0800 (CST)
subject:user1 to user2
Message-Id: <20130810064402.8E04DC4C1A@mail.sxkj.com>
Date: Sat, 10 Aug 2013 14:43:55 +0800 (CST)
From: user1@sxkj.com
To: 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.conf
listen = *
ssl_disable = yes
protocols = pop3 imap
disable_plaintext_auth = no
mail_location = maildir:~/Maildir

#POP3收信测试:telnet  localhost  110

[root@mail ~]# telnet  mail  110

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 10.0.1.88...
Connected to mail.
Escape character is '^]'.
+OK Dovecot ready.
USER user1
+OK
PASS 123
+OK Logged in.
LIST
+OK 1 messages:
1 518
.
RETR 1
+OK 518 octets
Return-Path: <root@sxkj.com>
X-Original-To: user1
Delivered-To: user1@sxkj.com
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 +0800
To: user1@sxkj.com
Subject: root to user1
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20130810063715.0C3E4C1766@mail.sxkj.com>
From: root@sxkj.com (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 restart
Stopping 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 restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]