50010623 发表于 2015-11-24 10:11:20

ubuntu下postfix邮件服务器安装

一,安装Postfix和相关软件包
1.安装Postfix
view plaincopyprint?
1.   apt-get install postfix
在安装的过程中,会提示输入选择类型和域名。分别填写"only localhost"和"localhost"

2.安装mailx软件包
view plaincopyprint?
1.   apt-get install mailutils
mailx软件包是一个命令行的邮件属性程序,mail命令包含在mailx软件包里面

二,测试你的默认设置
1.添加测试用户(以fmaster为例)
view plaincopyprint?
1.   useradd -m -s /bin/bash fmaster
2.   passwd fmaster
这里密码设置为test1234。在后述的测试中会用到。

2.用下面的命令测试,其实就是测试25端口是否打开
view plaincopyprint?
1.   telnet localhost 25
3.Postfix将在终端中显示如下提示,这样你就可以用来键入SMTP命令.
view plaincopyprint?
1.   root@ubuntu:~# telnet localhost 25
2.   Trying 127.0.0.1...
3.   Connected to localhost.
4.   Escape character is '^]'.
5.   220 ubuntu ESMTP Postfix (Ubuntu)
4.编写邮件并发送
view plaincopyprint?
1.   root@ubuntu:~# telnet localhost 25
2.   Trying 127.0.0.1...
3.   Connected to localhost.
4.   Escape character is '^]'.
5.   220 ubuntu ESMTP Postfix (Ubuntu)
6.   ehlo localhost               //   
7.   250-ubuntu
8.   250-PIPELINING
9.   250-SIZE 10240000
10.250-VRFY
11.250-ETRN
12.250-STARTTLS
13.250-ENHANCEDSTATUSCODES
14.250-8BITMIME
15.250 DSN
16.mail from: root@localhost    //   
17.250 2.1.0 Ok
18.rcpt to: fmaster@localhost   //   
19.250 2.1.5 Ok
20.data                         //
21.354 End data with <CR><LF>.<CR><LF>
22.Subject: My first mail on Postfix    //
23.this ia the first postfix mail .   //
24..                                    //
25.250 2.0.0 Ok: queued as 661C75F796
26.quit                                 //
27.221 2.0.0 Bye
28.Connection closed by foreign host.
5.切换到fmaster用户,查看邮件
view plaincopyprint?
1.   root@ubuntu:~# su - fmaster
2.   fmaster@ubuntu:~$ mail
3.   &quot;/var/mail/fmaster&quot;: 1 message 1 new
4.   >N   1 root@localhost   火1月 29 12:12/435   My first mail on Postfix
此时的邮件存放在/var/mail/fmaster文件中。
当这个邮件被打开之后,Postfix就会以mbox的风格处理邮件,
将邮件都保存到/home/fmaster/mbox这一个文件中。

6.设置Postfix以支持Maildir风格的邮箱(在修改配置之前备份配置文件)
view plaincopyprint?
1.   cp -pf /etc/postfix/main.cf /etc/postfix/main.cf_bak
2.   vim /etc/postfix/main.cf
在文件中末尾处,添加如下配置:
view plaincopyprint?
1.   home_mailbox=Maildir/
7.重启postfix,以使配置生效
view plaincopyprint?
1.   /etc/init.d/postfix restart
8.测试
view plaincopyprint?
1.   root@ubuntu:/etc/postfix# telnet localhost 25
2.   Trying 127.0.0.1...
3.   Connected to localhost.
4.   Escape character is '^]'.
5.   220 ubuntu ESMTP Postfix (Ubuntu)
6.   ehlo localhost                     //   
7.   250-ubuntu
8.   250-PIPELINING
9.   250-SIZE 10240000
10.250-VRFY
11.250-ETRN
12.250-STARTTLS
13.250-ENHANCEDSTATUSCODES
14.250-8BITMIME
15.250 DSN
16.mail from: root@localhost            //   
17.250 2.1.0 Ok
18.rcpt to: fmaster@localhost         //   
19.250 2.1.5 Ok
20.data                                 //   
21.354 End data with <CR><LF>.<CR><LF>
22.Subject: maildir test                   //   
23.this is a maildir style mail test .   //   
24..                                       //   
25.250 2.0.0 Ok: queued as 249315F80D
26.quit                                    //   
27.221 2.0.0 Bye
28.Connection closed by foreign host.
9.查收邮件这个时候Postfix会在/home/fmaster目录下面生成一个名为Maildir的文件夹,所有的邮件都保存在/home/fmaster/Maildir这个文件夹内。
view plaincopyprint?
1.   fmaster@ubuntu:~$ ll /home/fmaster/Maildir
2.   合計 20
3.   drwx------ 5 fmaster fmaster 40961月 29 12:35 ./
4.   drwxr-xr-x 3 fmaster fmaster 40961月 29 12:35 ../
5.   drwx------ 2 fmaster fmaster 40961月 29 12:35 cur/
6.   drwx------ 2 fmaster fmaster 40961月 29 12:35 new/
7.   drwx------ 2 fmaster fmaster 40961月 29 12:35 tmp/
8.   
9.   fmaster@ubuntu:~/Maildir$ cd new
10.
11.fmaster@ubuntu:~/Maildir/new$ ll
12.合計 12
13.drwx------ 2 fmaster fmaster 40961月 29 12:35 ./
14.drwx------ 5 fmaster fmaster 40961月 29 12:35 ../
15.-rw------- 1 fmaster fmaster4261月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu
16.
17.fmaster@ubuntu:~/Maildir/new$ less 1359430545.Vfc00I16daM671946.ubuntu
18.Return-Path: <root@localhost>
19.X-Original-To: fmaster@localhost
20.Delivered-To: fmaster@localhost
21.Received: from localhost (localhost )
22.      by ubuntu (Postfix) with ESMTP id 249315F80D
23.      for <fmaster@localhost>; Tue, 29 Jan 2013 12:35:13 &#43;0900 (JST)
24.Subject: maildir test
25.Message-Id: <20130129033517.249315F80D@ubuntu>
26.Date: Tue, 29 Jan 2013 12:35:13 &#43;0900 (JST)
27.From: root@localhost
28.
29.this is a maildir style mail test .
30.1359430545.Vfc00I16daM671946.ubuntu (END)
到此为止发送邮件的服务器就搭建成功了,接下来配置收信服务器。
在配置收信服务器中,需要使用到域名,如果没有域名可以修改hosts文件来进行测试。
下面配置中用到的域名: dotuian.com
邮件服务器的IP地址: 192.168.0.114 (ubutun)
测试客户端         : 192.168.0.80(windows 7)

三,配置收信服务器
1.修改邮件服务器的hosts文件
view plaincopyprint?
1.   vim /etc/hosts
在文件中添加
view plaincopyprint?
1.   127.0.0.1       dotuian.com
2.修改测试客户端的hosts文件
以管理员权限运行一个文本编辑器,打开&quot;C:\Windows\System32\drivers\etc\hosts&quot;,在里面添加
view plaincopyprint?
1.   192.168.0.114   dotuian.com
如果已经存在域名了,就不要上述的修改hosts文件的两步了。
3.安装收信服务器
view plaincopyprint?
1.   apt-get install courier-pop
2.   apt-get install courier-imap
4.修改配置文件
view plaincopyprint?
1.   vim /etc/postfix/main.cf
(a)将域名增加到&quot;mydestination&quot;。配置如下
view plaincopyprint?
1.   mydestination = localhost, ubuntu, localhost.localdomain, localhost, dotuian.com
(b)将本地网络增加到&quot;mynetworks&quot;。因为服务器IP地址为192.168.0.114,所以配置如下
view plaincopyprint?
1.   mynetworks = 192.168.0.0/24, 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
(c)为了能够通过网络接受邮件,修改&quot;inet_interfaces&quot;为&quot;all&quot;
view plaincopyprint?
1.   #inet_interfaces = loopback-only
2.   inet_interfaces = all

5.重启postfix服务器
view plaincopyprint?
1.   /etc/init.d/postfix restart
6.测试域名配置是否成功(a)通过域名dotuian.com发送邮件
view plaincopyprint?
1.   root@ubuntu:/etc/postfix# telnet dotuian.com 25
2.   Trying 127.0.0.1...
3.   Connected to dotuian.com.
4.   Escape character is '^]'.
5.   220 ubuntu ESMTP Postfix (Ubuntu)
6.   ehlo dotuian.com                      //
7.   250-ubuntu
8.   250-PIPELINING
9.   250-SIZE 10240000
10.250-VRFY
11.250-ETRN
12.250-STARTTLS
13.250-ENHANCEDSTATUSCODES
14.250-8BITMIME
15.250 DSN
16.mail from: shou@dotuian.com          //
17.250 2.1.0 Ok
18.rcpt to: fmaster@dotuian.com         //
19.250 2.1.5 Ok
20.data                                 //
21.354 End data with <CR><LF>.<CR><LF>
22.Subject: mail test with domain       //
23.this is a test mail .                //
24.dotuian.com                        //
25..
26.250 2.0.0 Ok: queued as 9E95D5F809
27.quit                                 //
28.221 2.0.0 Bye
29.Connection closed by foreign host.
(b)查收邮件检查/home/fmaster/Maildir/new,可以看到新建了一个独立的文件
view plaincopyprint?
1.   fmaster@ubuntu:~/Maildir/new$ ll
2.   合計 16
3.   drwx------ 2 fmaster fmaster 40961月 29 14:10 ./
4.   drwx------ 5 fmaster fmaster 40961月 29 12:35 ../
5.   -rw------- 1 fmaster fmaster4261月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu
6.   -rw------- 1 fmaster fmaster4461月 29 14:10 1359436215.Vfc00I16d8M538132.ubuntu
7.   
8.   <span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;>fmaster@ubuntu:~/Maildir/new$ less 1359436215.Vfc00I16d8M538132.ubuntu</span>
9.   
10.<span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;>Return-Path: <shou@dotuian.com></span>
11.X-Original-To: fmaster@dotuian.com
12.Delivered-To: fmaster@dotuian.com
13.Received: from dotuian.com (localhost )
14.      by ubuntu (Postfix) with ESMTP id 9E95D5F809
15.      for <fmaster@dotuian.com>; Tue, 29 Jan 2013 14:09:35 &#43;0900 (JST)
16.Subject: mail test with domain
17.Message-Id: <20130129050947.9E95D5F809@ubuntu>
18.Date: Tue, 29 Jan 2013 14:09:35 &#43;0900 (JST)
19.From: shou@dotuian.com
20.
21.<span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;>this is a test mail .</span>
22.dotuian.com
23.1359436215.Vfc00I16d8M538132.ubuntu (END)
7.测试Courier POP3
view plaincopyprint?
1.   root@ubuntu:/etc/postfix# telnet dotuian.com 110
2.   Trying 127.0.0.1...
3.   Connected to dotuian.com.
4.   Escape character is '^]'.
5.   &#43;OK Hello there.
6.   user fmaster          //
7.   &#43;OK Password required.
8.   pass test1234         //
9.   &#43;OK logged in.
10.quit                  //
11.&#43;OK Bye-bye.
12.Connection closed by foreign host.
8.测试 Courier IMAP
view plaincopyprint?
1.   root@ubuntu:/etc/postfix# telnet dotuian.com 143
2.   Trying 127.0.0.1...
3.   Connected to dotuian.com.
4.   Escape character is '^]'.
5.   * OK Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc.See COPYING for distribution information.
6.   a login fmaster test1234            //
7.   a OK LOGIN Ok.
8.   a logout                            //
9.   * BYE Courier-IMAP server shutting down
10.a OK LOGOUT completed
11.Connection closed by foreign host.
  9.通过Microsoft Outlook收发邮件是的配置

  
  
页: [1]
查看完整版本: ubuntu下postfix邮件服务器安装