/ 中存储网

Postfix+Dovecot邮局服务配置过程指南

2014-07-13 20:08:56 来源:中存储网

配置环境CentOS5.5,查询CentOS版本命令如下:

[root@localhost ~]# lsb_release -a
LSB Version:    :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description:    CentOS release 5.5 (Final)
Release:        5.5
Codename:       Final

 

关闭sendmail

[root@localhost ~]# /etc/init.d/sendmail stop

关闭sendmail自启动:

[root@localhost ~]# chkconfig sendmail off

1. 在CentOS5.5中使用yum install postfix会安装postfix-2.3.3-2.3.el5_6,当我们配置使用dovecot认证的时候会出现错误fatal: no SASL authentication mechanisms

2. 在CentOS5.5中使用yum install dovecot会安装dovecot-1.0.7-7.el5,会出现private/auth没有权限问题

正确方法,下载dovecot-1.2.17.tar.gz      postfix-2.7.3.tar.gz

 

创建用户

useradd -s /sbin/nologin -d /dev/null dovecot

tar -zxvf dovecot-1.2.17.tar.gz     

cd dovecot-1.2.17

./configure && make && make install

cp /usr/local/etc/dovecot-example.conf /usr/local/etc/dovecot.conf

配置dovecot

vi /usr/local/etc/dovecot.conf
base_dir = /var/run/dovecot/
protocols = imap   pop3 (修改)
listen = *
ssl_disable = yes
login_dir = /var/run/dovecot/login
login_user = dovecot
default_mail_env = maildir:/var/mail/vhosts/%d/%n/   (修改)
disable_plaintext_auth = no
pop3_uidl_format = %v
passdb passwd-file {
     # Path for passwd-file
     args = /etc/postfix/passwd
   }
userdb passwd-file {
     # Path for passwd-file
     args = /etc/postfix/passwd
   }

     auth default {   (默认打开)
       mechanisms = plain login (修改)
  
       socket listen {
         client {
           path = /var/spool/postfix/private/auth
           mode = 0660
           user = postfix
           group = postfix
         }
       }
}

 

 

安装POSTFIX
建立用户
groupadd -g 12345 postfix
useradd -u 12345 -g postfix -s /sbin/nologin -d /dev/null postfix
groupadd -g 54321 postdrop
groupadd -g 5000 vmail
useradd -u 5000 -g vmail -s /sbin/nologin -d /dev/null vmail
安装
tar -zxvf postfix-2.7.3.tar.gz
cd postfix-2.7.3

make makefiles CCARGS='-DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE="dovecot"'
make
make install
(一路回车)
3, 修改main.cf
vi /etc/postfix/main.cf:
##添加如下代码
#smtp auth   (SMTP 认证)
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_sasl_authenticated permit_auth_destination reject
#virtual mailbox domain
virtual_mailbox_domains=/etc/postfix/vdomains
virtual_mailbox_base=/var/mail/vhosts
virtual_mailbox_maps=hash:/etc/postfix/vmailbox
virtual_mailbox_uid=100
virtual_uid_maps=static:5000
virtual_gid_maps=static:5000
virtual_alias_maps=hash:/etc/postfix/virtual
添加域名,添加用户
例如要添加的域名:test.com,添加的用户:test@test.com 密码test
1,添家域名
vi /etc/postfix/vdomains
test.com
2,添加用户
vi /etc/postfix/vmailbox
test@test.com test.com/test/
mkdir /var/mail/vhosts
chown vmail.vmail /var/mail/vhosts
postmap /etc/postfix/vdomains
postmap /etc/postfix/vmailbox
postmap /etc/postfix/virtual
3,建立密码文件
vi /etc/postfix/passwd
test@test.com:{plain}test:5000:5000::/var/mail/vhosts/test.com/test/
用户名:{plain}密码:(邮件存储目录的用户和组):: 邮件存储目录
以后在添加用户的时候
添加存在域的用户
test2@test.com   密码:test2
1,修改 vmailbox
/etc/postfix/vmailbox
test2@test.com test.com/test2/
#postmap /etc/postfix/vmailbox
2,修改passwd
/etc/postfix/passwd
test2@test.com:{plain} test2:5000:5000::/var/mail/vhosts/test.com/test2/

添加不存在域的用户,先建立域名
test@abc.com 密码:test2006
1,修改vdomains 添加 abc.com
vi /etc/postfix/vdomains
abc.com
2,修改 vmailbox
test@abc.com abc.com/test/
#postmap /etc/postfix/vmailbox
3,修改 pssswd
test@abc.com:{plain}test2006:5000:5000::/var/mail/vhosts/ abc.com/test/
centos系统安装POSTFIX时需要重新注册下
修改/etc/postfix/main.cf
aliases map   的位置   指向/etc/postfix/aliases
aliases db   的位置   指向/etc/postfix/aliases
执行
newaliases
七,   启动
#dovecot
#postfix start
八, 测试
#netstat –nlp
查看 110,25 ,143   端口是否开放
通过以下命令获得test@test.com的用户名及密码的BASE64编码:
perl -e 'use MIME::Base64; print encode_base64("test@test.com")'
dGVzdC5jb20=
perl -e 'use MIME::Base64; print encode_base64("test")'
dGVzdA==
然后本机测试,其过程如下(蓝色的文字是我们输入/发送到Postfix的)
[root@smtp root]# telnet localhost 25
Trying 127.0.0.1...
Connected to smtp.test.com (127.0.0.1).
Escape character is '^]'.
220 smtp.trade.abc.cn ESMTP Postfix
ehlo aa.com
250-smtp.test.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
dGVzdC5jb20=
334 UGFzc3dvcmQ6
dGVzdA==
235 2.0.0 Authentication successful
mail from:<test@163.com>
250 2.1.0 Ok
rcpt to:<test@test.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
good mail
.
250 2.0.0 Ok: queued as 1F2706FDDA
出现235 Authentication Successful 表明认证成功了。
这样 就以test@163.com发送一封邮件给刚建立的用户 test@test.com

如果上面方式行不通:使用如下测试

[root@localhost sasl2]# perl -MMIME::Base64 -e
>     'print encode_base64("test@test.comtest@test.comtest")';
dGVzdEB0ZXN0LmNvbQB0ZXN0QHRlc3QuY29tAHRlc3Q=
[root@localhost sasl2]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 smtp.test.com ESMTP Postfix
auth plain dGVzdEB0ZXN0LmNvbQB0ZXN0QHRlc3QuY29tAHRlc3Q=
235 2.7.0 Authentication successful

 

postfix warning: dict_nis_init: NIS domain name not set - NIS lookups disabled 解决方法
[root@mail postfix]# postalias /etc/postfix/aliases 
在/etc/postfix/main.cf中加入下面配置信息
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases

测试 110

[root@smtp root]# telnet localhost 110
Trying 127.0.0.1...
Connected to smtp.test.com (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user

test@test.com
+OK
pass test
+OK Logged in.
list
+OK 1 messages:
retr 1
dele 1
1 481