Postfix+Dovecot邮件服务器架设傻瓜版指南

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
头像
37圈半
帖子: 3
注册时间: 2008-06-23 11:04

Postfix+Dovecot邮件服务器架设傻瓜版指南

#1

帖子 37圈半 » 2008-11-24 13:31

有几个兄弟想建email服务器,按照wiki死活搞不通,找我写了个傻瓜版教程。
我看了一下,wiki里的确好像有些混乱,就写了。写完就不浪费,顺便贴到坛子里,希望能对有需要的人有点帮助作用
---------------------------------------

需求:
建立EMail服务器,提供SMTP和POP3服务,客户用foxmail或者outlook收发信件。

前提:
域名(mail.example.com)、固定IP、DNS上设置好A、MX、PTR记录

使用软件:
Ubuntu 8.04 Server, Postfix, Dovecot

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

步骤:
1、装好Ubuntu 8.04,update
注意:如果DNS上PTR记录正确的话,安装过程中系统会自动发现你的主机名和域名。

2、安装postfix
sudo apt-get install postfix
安装完成后,系统会自动提示进行一些基本信息设置。默认即可。

3、初始配置postfix
sudo dpkg-reconfigure postfix
默认即可,反正事后可以在main.cf里改

4、配置main.cf
main.cf文件在/etc/postfix下
在mydestination后加上example.com,成为这个样子:
mydestination = example.com, mail.example.com, localhost.example.com, localhost
这是因为默认情况postfix只接收发到@mail.example.com的邮件,而不接收@example.com的邮件。

5、更改mailbox类型
sudo postconf -e 'home_mailbox = Maildir/'
注:postconf -e和在mail.cf自己写是一回事,-e for edit
这个步骤其实为可选操作。mailbox类型可以是mbox或者是maildir,互有优缺点。但如果将来还打算扩展webmail这类应用,最好选为Maildir,这样兼容性更好一些。对于dovecot pop3而言,倒是无所谓了。具体mbox和maildir有什么区别,去参考《postfix权威指南》

6、安装dovecot
sudo apt-get install dovecot-pop3d
系统会自动带上dovecot-common,后面配置sasl认证的时候就不用再装了

7、编辑dovecot.conf
主要有两个地方:
mail_location = maildir:~/Maildir
#我们前面设置了mailbox类型为maildir,这是对应的设置。
disable_plaintext_auth = no
#默认情况下,dovecot是不允许plaintext类型的认证的,打开

------------------
重启postfix和dovecot。至此,postfix可以收信,并且foxmail可以pop3取信。测试。
到现在foxmail还不能连接到postfix发信,原因是postfix不进行open relay,OR可不能打开,太危险了。
两种解决方案:
a、在mail.cf里的mynetworks字段加上foxmail所在的网段。默认情况下mynetworks字段只有127.0.0.0/8,所以你telnet mail.example.com 25 后,是可以发信的。如果你确定foxmail所在的网段,加上即可。
b、很多情况下发信客户ip是不能确定的,所以打开sasl认证。
接下来配置sasl认证
------------------

8、编辑dovecot.conf
在mechanisms字段加上login,成为这个样子:
mechanisms = plain login
编辑socket listen字段,成为这个样子:
socket listen {
client {
path = /var/spool/postfix/private/auth-client
mode = 0660
user = postfix
group = postfix
}
}
9、给postfix加上如下配置
sudo postconf -e 'smtpd_sasl_type = dovecot'
sudo postconf -e 'smtpd_sasl_path = private/auth-client'
sudo postconf -e 'smtpd_sasl_local_domain ='
sudo postconf -e 'smtpd_sasl_security_options = noanonymous'
sudo postconf -e 'broken_sasl_auth_clients = yes'
sudo postconf -e 'smtpd_sasl_auth_enable = yes'
sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
sudo postconf -e 'inet_interfaces = all'
10、重起postfix和dovecot。不出意外的话,已经可以通过foxmail正常收发邮件了


注:
1、这样的配置对认证过程不加密,如果害怕密码被监听,就进一步加上ssl好了。
2、如果被hotmail等退信的话。大部分情况下有两种可能:a、没有PTR记录,找你的ISP做。b、你的IP属于垃圾邮件监控地址(俗称上榜,呵呵),去查查看。比如www.spamhaus.org(hotmail就是用这个的),如果属于pbl,申请取消就好了,如果sbl这些,那就只能找你的ISP解决了。gmail则比较奇怪。如果gmail退信的话,试着改一下mail.cf中mydestination的顺序,把localhost改到前面。改成这个样子:
“mydestination = localhost, localhost.example.com, mail.example.com, example.com”
很多人就这样把问题解决了,但似乎谁都不知道原理 :)
头像
aesnmxb
帖子: 29
注册时间: 2008-07-08 18:34

Re: Postfix+Dovecot邮件服务器架设傻瓜版指南

#2

帖子 aesnmxb » 2008-11-24 14:44

按楼主的装完了,但不会测试,最好加上web管理,这样对一个菜鸟那就是最好的啦。
9981
帖子: 200
注册时间: 2007-05-19 16:24

Re: Postfix+Dovecot邮件服务器架设傻瓜版指南

#3

帖子 9981 » 2008-11-29 9:25

能说一说postfix+webmail+非系统用户吗?
在系统里见到过几张贴子,但功力太差。
也能出个傻瓜版的教材吗?
9981 学习的过程
http://abcde.blog.ubuntu.org.cn/
blog上的都是原来学习时的记录,现在来看,还需重新整理
ubuntu-server-8.04-lts
我想在日常的工作和生活中应该更多的使用linux
绝对新手
学以致用
爱上那只猪
帖子: 263
注册时间: 2008-07-11 16:23

Re: Postfix+Dovecot邮件服务器架设傻瓜版指南

#4

帖子 爱上那只猪 » 2009-11-20 16:44

好贴。收藏了!
谢谢老师!
saiman
帖子: 9
注册时间: 2009-06-10 11:24

Re: Postfix+Dovecot邮件服务器架设傻瓜版指南

#5

帖子 saiman » 2009-11-25 13:47

强烈支持,最好加上WebMail和Mail虚拟用户的管理,那就更实用了。
Linux资深爱好者。
企业信息化推进者。
电子商务实施者。
leonwei
帖子: 30
注册时间: 2008-03-15 17:42

Re: Postfix+Dovecot邮件服务器架设傻瓜版指南

#6

帖子 leonwei » 2009-11-27 13:01

据我经验,只需apt-get install postfix postfix-mysql dovecot-imapd dovecot-pop3d dovecot-postfix,正确安装后即可正常使用系统帐户收发邮件,默认是打开ssl的。

完全不用再做任何设置。
回复