2014-12-22 13:01:04
来 源
中存储网
Postfix
今天学会了在ubuntu上配置邮件服务器。一直以为很容易,真的要配了才知道不容易,都弄完了急得一身汗。中间参考了很多资料,还尝试了好几种方案,最终用Postfix+Dovecot完成任务。过程如下,为避免忘了,今晚在VPS上再配置一次,加深印象。1、装好Ubu

今天学会了在ubuntu上配置邮件服务器。一直以为很容易,真的要配了才知道不容易,都弄完了急得一身汗。中间参考了很多资料,还尝试了好几种方案,最终用Postfix+Dovecot完成任务。

过程如下,为避免忘了,今晚在VPS上再配置一次,加深印象。

1、装好Ubuntu

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、编辑/etc/dovecot/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(sudo service postfix restart)和dovecot(sudo service dovecot restart)。不出意外的话,已经可以通过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”
很多人就这样把问题解决了,但似乎谁都不知道原理 :)

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。