设为首页 收藏本站
查看: 2074|回复: 0

[经验分享] Ubuntu13.10 下Postfix 邮件服务器安装及基本的设置

[复制链接]

尚未签到

发表于 2015-9-15 10:39:46 | 显示全部楼层 |阅读模式
在我们建立邮件服务器的时候遇到了几个问题,发送不了邮件,查了资料后发现:配置变量relay_domains =  在这里面进行域名的过滤设置

一,安装Postfix和相关软件包
1.安装Postfix
apt-get install postfix  
在安装的过程中,会提示输入选择类型和域名。
2.安装mailx软件包
apt-get install mailutils
mailx软件包是一个命令行的邮件属性程序,mail命令包含在mailx软件包里面
二,测试你的默认设置
1.添加测试用户(以s为例)
useradd -m -s /bin/bash s
passwd s
这里密码设置为123456。在后述的测试中会用到。
2.用下面的命令测试,其实就是测试25端口是否打开
telnet localhost 25
3.Postfix将在终端中显示如下提示,这样你就可以用来键入SMTP命令.


  • root@ubuntu:~# telnet localhost 25
  • Trying 127.0.0.1...
  • Connected to localhost.
  • Escape character is '^]'.
  • 220 ubuntu ESMTP Postfix (Ubuntu)
4.编写邮件并发送
root@ubuntu:~# telnet localhost 25
Trying 127.0.0.1...  
Connected to localhost.  
Escape character is '^]'.
220 ubuntu ESMTP Postfix (Ubuntu)  
ehlo localhost               //   
250-ubuntu  
250-PIPELINING  
250-SIZE 10240000  
250-VRFY  
250-ETRN  
250-STARTTLS  
250-ENHANCEDSTATUSCODES  
250-8BITMIME  
250 DSN  
mail from: root@localhost    //   
250 2.1.0 Ok  
rcpt to: fmaster@localhost   //   
250 2.1.5 Ok  
data                         //  
354 End data with .  
Subject: My first mail on Postfix    //  
this ia the first postfix mail .     //  
.                                    //  
250 2.0.0 Ok: queued as 661C75F796  
quit                                 //  
221 2.0.0 Bye  
Connection closed by foreign host.  5.切换到fmaster用户,查看邮件
root@ubuntu:~# su - fmaster  
fmaster@ubuntu:~$ mail  
"/var/mail/fmaster": 1 message 1 new  
>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风格的邮箱(在修改配置之前备份配置文件)


[plain] view plaincopyprint?

  • cp -pf /etc/postfix/main.cf /etc/postfix/main.cf_bak
  • vim /etc/postfix/main.cf
在文件中末尾处,添加如下配置:


[plain] view plaincopyprint?

  • home_mailbox=Maildir/
7.重启postfix,以使配置生效


[plain] view plaincopyprint?

  • /etc/init.d/postfix restart
8.测试

[plain] view plaincopyprint?

  • root@ubuntu:/etc/postfix# telnet localhost 25
  • Trying 127.0.0.1...
  • Connected to localhost.
  • Escape character is '^]'.
  • 220 ubuntu ESMTP Postfix (Ubuntu)
  • ehlo localhost                       //
  • 250-ubuntu
  • 250-PIPELINING
  • 250-SIZE 10240000
  • 250-VRFY
  • 250-ETRN
  • 250-STARTTLS
  • 250-ENHANCEDSTATUSCODES
  • 250-8BITMIME
  • 250 DSN
  • mail from: root@localhost            //
  • 250 2.1.0 Ok
  • rcpt to: fmaster@localhost           //
  • 250 2.1.5 Ok
  • data                                 //
  • 354 End data with .
  • Subject: maildir test                   //
  • this is a maildir style mail test .     //
  • .                                       //
  • 250 2.0.0 Ok: queued as 249315F80D
  • quit                                    //
  • 221 2.0.0 Bye
  • Connection closed by foreign host.
9.查收邮件这个时候Postfix会在/home/fmaster目录下面生成一个名为Maildir的文件夹,所有的邮件都保存在/home/fmaster/Maildir这个文件夹内。


[plain] view plaincopyprint?

  • fmaster@ubuntu:~$ ll /home/fmaster/Maildir
  • 合計 20
  • drwx------ 5 fmaster fmaster 4096  1月 29 12:35 ./
  • drwxr-xr-x 3 fmaster fmaster 4096  1月 29 12:35 ../
  • drwx------ 2 fmaster fmaster 4096  1月 29 12:35 cur/
  • drwx------ 2 fmaster fmaster 4096  1月 29 12:35 new/
  • drwx------ 2 fmaster fmaster 4096  1月 29 12:35 tmp/

  • fmaster@ubuntu:~/Maildir$ cd new

  • fmaster@ubuntu:~/Maildir/new$ ll
  • 合計 12
  • drwx------ 2 fmaster fmaster 4096  1月 29 12:35 ./
  • drwx------ 5 fmaster fmaster 4096  1月 29 12:35 ../
  • -rw------- 1 fmaster fmaster  426  1月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu

  • fmaster@ubuntu:~/Maildir/new$ less 1359430545.Vfc00I16daM671946.ubuntu
  • Return-Path:
  • X-Original-To: fmaster@localhost
  • Delivered-To: fmaster@localhost
  • Received: from localhost (localhost [127.0.0.1])
  •         by ubuntu (Postfix) with ESMTP id 249315F80D
  •         for ; Tue, 29 Jan 2013 12:35:13 +0900 (JST)
  • Subject: maildir test
  • Message-Id: <20130129033517.249315F80D@ubuntu>
  • Date: Tue, 29 Jan 2013 12:35:13 +0900 (JST)
  • From: root@localhost

  • this is a maildir style mail test .
  • 1359430545.Vfc00I16daM671946.ubuntu (END)
到此为止发送邮件的服务器就搭建成功了,接下来配置收信服务器。
在配置收信服务器中,需要使用到域名,如果没有域名可以修改hosts文件来进行测试。
下面配置中用到的域名: dotuian.com
邮件服务器的IP地址  : 192.168.0.114 (ubutun)
测试客户端          : 192.168.0.80  (windows 7)
三,配置收信服务器
1.修改邮件服务器的hosts文件

[plain] view plaincopyprint?

  • vim /etc/hosts
在文件中添加

[plain] view plaincopyprint?

  • 127.0.0.1       dotuian.com
2.修改测试客户端的hosts文件
以管理员权限运行一个文本编辑器,打开"C:\Windows\System32\drivers\etc\hosts",在里面添加


[plain] view plaincopyprint?

  • 192.168.0.114   dotuian.com
如果已经存在域名了,就不要上述的修改hosts文件的两步了。
3.安装收信服务器


[plain] view plaincopyprint?

  • apt-get install courier-pop
  • apt-get install courier-imap
4.修改配置文件

[plain] view plaincopyprint?

  • vim /etc/postfix/main.cf
  (a)将域名增加到"mydestination"。配置如下


[plain] view plaincopyprint?

  • mydestination = localhost, ubuntu, localhost.localdomain, localhost, dotuian.com
  (b)将本地网络增加到"mynetworks"。因为服务器IP地址为192.168.0.114,所以配置如下


[plain] view plaincopyprint?

  • mynetworks = 192.168.0.0/24, 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  (c)为了能够通过网络接受邮件,修改"inet_interfaces"为"all"


[plain] view plaincopyprint?

  • #inet_interfaces = loopback-only
  • inet_interfaces = all

5.重启postfix服务器

[plain] view plaincopyprint?

  • /etc/init.d/postfix restart
6.测试域名配置是否成功(a)通过域名dotuian.com发送邮件

[plain] view plaincopyprint?

  • root@ubuntu:/etc/postfix# telnet dotuian.com 25
  • Trying 127.0.0.1...
  • Connected to dotuian.com.
  • Escape character is '^]'.
  • 220 ubuntu ESMTP Postfix (Ubuntu)
  • ehlo dotuian.com                      //
  • 250-ubuntu
  • 250-PIPELINING
  • 250-SIZE 10240000
  • 250-VRFY
  • 250-ETRN
  • 250-STARTTLS
  • 250-ENHANCEDSTATUSCODES
  • 250-8BITMIME
  • 250 DSN
  • mail from: shou@dotuian.com          //
  • 250 2.1.0 Ok
  • rcpt to: fmaster@dotuian.com         //
  • 250 2.1.5 Ok
  • data                                 //
  • 354 End data with .
  • Subject: mail test with domain       //
  • this is a test mail .                //
  • dotuian.com                          //
  • .
  • 250 2.0.0 Ok: queued as 9E95D5F809
  • quit                                 //
  • 221 2.0.0 Bye
  • Connection closed by foreign host.
(b)查收邮件检查/home/fmaster/Maildir/new,可以看到新建了一个独立的文件


[plain] view plaincopyprint?

  • fmaster@ubuntu:~/Maildir/new$ ll
  • 合計 16
  • drwx------ 2 fmaster fmaster 4096  1月 29 14:10 ./
  • drwx------ 5 fmaster fmaster 4096  1月 29 12:35 ../
  • -rw------- 1 fmaster fmaster  426  1月 29 12:35 1359430545.Vfc00I16daM671946.ubuntu
  • -rw------- 1 fmaster fmaster  446  1月 29 14:10 1359436215.Vfc00I16d8M538132.ubuntu

  • fmaster@ubuntu:~/Maildir/new$ less 1359436215.Vfc00I16d8M538132.ubuntu

  • Return-Path:
  • X-Original-To: fmaster@dotuian.com
  • Delivered-To: fmaster@dotuian.com
  • Received: from dotuian.com (localhost [127.0.0.1])
  •         by ubuntu (Postfix) with ESMTP id 9E95D5F809
  •         for ; Tue, 29 Jan 2013 14:09:35 +0900 (JST)
  • Subject: mail test with domain
  • Message-Id: <20130129050947.9E95D5F809@ubuntu>
  • Date: Tue, 29 Jan 2013 14:09:35 +0900 (JST)
  • From: shou@dotuian.com

  • this is a test mail .
  • dotuian.com
  • 1359436215.Vfc00I16d8M538132.ubuntu (END)
7.测试Courier POP3

[plain] view plaincopyprint?

  • root@ubuntu:/etc/postfix# telnet dotuian.com 110
  • Trying 127.0.0.1...
  • Connected to dotuian.com.
  • Escape character is '^]'.
  • +OK Hello there.
  • user fmaster          //
  • +OK Password required.
  • pass test1234         //
  • +OK logged in.
  • quit                  //
  • +OK Bye-bye.
  • Connection closed by foreign host.
8.测试 Courier IMAP

[plain] view plaincopyprint?

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-113858-1-1.html 上篇帖子: Data Structure Stack: Infix to Postfix 下篇帖子: Postfix 发送邮件流程简析
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表