postfix配置过程

`
一、配置postfix
1、建立配置文件

#postconf -n > /etc/postfix/main2.cf

#mv /etc/postfix/main.cf /etc/postfix/main.cf.old

#mv /etc/postfix/main2.cf /etc/postfix/main.cf2、再编辑main.cf:#vim /etc/postfix/main.cf添加以下内容

########################################

hostname

#mynetworks = 127.0.0.1
myhostname = mail.kkio.com
mydestination = $mynetworks $myhostname# banner
mail_name = Postfix - by KKIO.COM
smtpd_banner = $myhostname ESMTP $mail_name# response immediately
smtpd_error_sleep_time = 0s
unknown_local_recipient_reject_code = 450# extmail config here
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport = maildrop:

######################################################`

3、编辑mysql_virtual_alias_maps.cf

#vim /etc/postfix/mysql_virtual_alias_maps.cf

添加以下内容

###########################
user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = alias
select_field = goto
where_field = address

#############################

4、编辑mysql_virtual_domains_maps.cf

#vim /etc/postfix/mysql_virtual_domains_maps.cf

内容如下:

user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = domain
select_field = description
where_field = domain

#additional_conditions = and backupmx =’0’ and active =’1’

5、编辑mysql_virtual_mailbox_maps.cf

#vim /etc/postfix/mysql_virtual_mailbox_maps.cf

内容如下:

user = extmail
password = extmail
hosts = localhost
dbname = extmail
table = mailbox
select_field = maildir
where_field = username

#additional_conditions = and active = ‘1’

二、配置Courier-Authlib
安装Courier-Authlib

1、运行如下命令安装相关软件包

#rpm -ivh RPMS/libtool-libs-1.5.6-4.EL4.1.c4.3.i386.rpm
//返回错误信息
//warning: RPMS/libtool-libs-1.5.6-4.EL4.1.c4.3.i386.rpm: Header V3 DSA signature: NOKEY, key ID 443e1821
//Preparing… ########################################### [100%]
// file /usr/lib/libltdl.so.3 from install of libtool-libs-1.5.6-4.EL4.1.c4.3 conflicts with file from package libtool-ltdl-1.5.22-6.1

#rpm -ivh RPMS/courier-authlib-0.57-1hzq.i386.rpm

#rpm -ivh RPMS/courier-authlib-devel-0.57-1hzq.i386.rpm

#rpm -ivh RPMS/courier-authlib-mysql-0.57-1hzq.i386.rpm

2、编辑/etc/authlib/authmysqlrc文件,并将其内容清空,然后增加如下内容:

MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_PORT 3306
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD uidnumber
MYSQL_GID_FIELD gidnumber
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD homedir
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_SELECT_CLAUSE SELECT username,password,””,uidnumber,gidnumber,\
CONCAT(‘/home/domains/‘,homedir), \
CONCAT(‘/home/domains/‘,maildir), \
quota, \
name \
FROM mailbox \
WHERE username = ‘$(local_part)@$(domain)’

3、存盘退出后启动courier-authlib:

#/etc/init.d/courier-authlib start

如一切正常,命令行将返回如下信息:
Starting Courier authentication services: authdaemond

4、修改authdaemon socket目录权限

如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证:
chmod 755 /var/spool/authdaemon/

5、配置使用maildrop

编辑main.cf,增加:
virtual_transport = maildrop:
maildrop_destination_recipient_limit = 1

其次编辑master.cf,找到定义maildrop的那行,原来默认的内容:
maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}

改为:
maildrop unix - n n - - pipe
flags=DRhu user=vuser argv=maildrop -w 90 -d ${recipient}

增加投递用户

很多邮件系统文档都使用postfix这个用户(一般是uid=125)作为邮件存储,在使用
系统的virtual等投递时不存在问题,如果是改为maildrop则postfix会报错。不允许
通过pipe来以user=postfix来投递。

因此从长远角度考虑(参见1),专门开一个帐户来保存邮件比较好。这里:

groupadd -r -g 1000 vgroup
useradd -u 1000 -d /home/domains -s /bin/true -g vgroup vuser

这样就增加了一个uid=1000, gid=1000的用户vuser,组属于vgroup的。

以后如果要使用suexec也不会因为uid太低而造成问题了!

保存好所有修改,重新启动postfix